2024-04-10 16:31:04 +02:00
|
|
|
import * as React from 'react';
|
|
|
|
import { connect } from 'react-redux';
|
|
|
|
import { AppState } from '../../utils/types';
|
|
|
|
import WarningBox from './WarningBox';
|
|
|
|
import { _ } from '@joplin/lib/locale';
|
|
|
|
import { showMissingMasterKeyMessage } from '@joplin/lib/services/e2ee/utils';
|
|
|
|
import { localSyncInfoFromState } from '@joplin/lib/services/synchronizer/syncInfoUtils';
|
|
|
|
import Setting from '@joplin/lib/models/Setting';
|
2024-04-15 19:17:34 +02:00
|
|
|
import { ShareInvitation, ShareUserStatus } from '@joplin/lib/services/share/reducer';
|
|
|
|
import { substrWithEllipsis } from '@joplin/lib/string-utils';
|
2024-04-10 16:31:04 +02:00
|
|
|
|
|
|
|
interface Props {
|
|
|
|
themeId: number;
|
|
|
|
showMissingMasterKeyMessage: boolean;
|
|
|
|
hasDisabledSyncItems: boolean;
|
|
|
|
shouldUpgradeSyncTarget: boolean;
|
|
|
|
showShouldUpgradeSyncTargetMessage: boolean|undefined;
|
|
|
|
hasDisabledEncryptionItems: boolean;
|
|
|
|
mustUpgradeAppMessage: string;
|
2024-04-15 19:17:34 +02:00
|
|
|
shareInvitations: ShareInvitation[];
|
|
|
|
processingShareInvitationResponse: boolean;
|
2024-07-01 17:21:17 +02:00
|
|
|
showInvalidJoplinCloudCredential: boolean;
|
2024-04-10 16:31:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
export const WarningBannerComponent: React.FC<Props> = props => {
|
|
|
|
const warningComps = [];
|
|
|
|
|
|
|
|
const renderWarningBox = (screen: string, message: string) => {
|
|
|
|
return <WarningBox
|
|
|
|
key={screen}
|
|
|
|
themeId={props.themeId}
|
|
|
|
targetScreen={screen}
|
|
|
|
message={message}
|
|
|
|
testID='warning-box'
|
|
|
|
/>;
|
|
|
|
};
|
|
|
|
|
|
|
|
if (props.showMissingMasterKeyMessage) {
|
|
|
|
warningComps.push(renderWarningBox('EncryptionConfig', _('Press to set the decryption password.')));
|
|
|
|
}
|
|
|
|
if (props.hasDisabledSyncItems) {
|
|
|
|
warningComps.push(renderWarningBox('Status', _('Some items cannot be synchronised. Press for more info.')));
|
|
|
|
}
|
|
|
|
if (props.shouldUpgradeSyncTarget && props.showShouldUpgradeSyncTargetMessage !== false) {
|
|
|
|
warningComps.push(renderWarningBox('UpgradeSyncTarget', _('The sync target needs to be upgraded. Press this banner to proceed.')));
|
|
|
|
}
|
|
|
|
if (props.mustUpgradeAppMessage) {
|
|
|
|
warningComps.push(renderWarningBox('UpgradeApp', props.mustUpgradeAppMessage));
|
|
|
|
}
|
|
|
|
if (props.hasDisabledEncryptionItems) {
|
|
|
|
warningComps.push(renderWarningBox('Status', _('Some items cannot be decrypted.')));
|
|
|
|
}
|
2024-07-01 17:21:17 +02:00
|
|
|
if (props.showInvalidJoplinCloudCredential) {
|
|
|
|
warningComps.push(renderWarningBox('JoplinCloudLogin', _('Your Joplin Cloud credentials are invalid, please login.')));
|
|
|
|
}
|
2024-04-10 16:31:04 +02:00
|
|
|
|
2024-04-15 19:17:34 +02:00
|
|
|
const shareInvitation = props.shareInvitations.find(inv => inv.status === ShareUserStatus.Waiting);
|
|
|
|
if (
|
|
|
|
!props.processingShareInvitationResponse
|
|
|
|
&& !!shareInvitation
|
|
|
|
) {
|
|
|
|
const invitation = props.shareInvitations.find(inv => inv.status === ShareUserStatus.Waiting);
|
|
|
|
const sharer = invitation.share.user;
|
|
|
|
|
|
|
|
warningComps.push(renderWarningBox(
|
|
|
|
'ShareManager',
|
|
|
|
_('%s (%s) would like to share a notebook with you.',
|
2024-07-26 13:35:50 +02:00
|
|
|
substrWithEllipsis(sharer?.full_name ?? 'Unknown', 0, 48),
|
|
|
|
substrWithEllipsis(sharer?.email ?? 'Unknown', 0, 52)),
|
2024-04-15 19:17:34 +02:00
|
|
|
));
|
|
|
|
}
|
|
|
|
|
2024-04-10 16:31:04 +02:00
|
|
|
return warningComps;
|
|
|
|
};
|
|
|
|
|
|
|
|
export default connect((state: AppState) => {
|
|
|
|
const syncInfo = localSyncInfoFromState(state);
|
|
|
|
|
|
|
|
return {
|
|
|
|
themeId: state.settings.theme,
|
|
|
|
hasDisabledEncryptionItems: state.hasDisabledEncryptionItems,
|
|
|
|
noteSelectionEnabled: state.noteSelectionEnabled,
|
|
|
|
selectedFolderId: state.selectedFolderId,
|
|
|
|
notesParentType: state.notesParentType,
|
|
|
|
showMissingMasterKeyMessage: showMissingMasterKeyMessage(syncInfo, state.notLoadedMasterKeys),
|
|
|
|
hasDisabledSyncItems: state.hasDisabledSyncItems,
|
|
|
|
shouldUpgradeSyncTarget: state.settings['sync.upgradeState'] === Setting.SYNC_UPGRADE_STATE_SHOULD_DO,
|
|
|
|
mustUpgradeAppMessage: state.mustUpgradeAppMessage,
|
2024-04-15 19:17:34 +02:00
|
|
|
shareInvitations: state.shareService.shareInvitations,
|
|
|
|
processingShareInvitationResponse: state.shareService.processingShareInvitationResponse,
|
2024-07-01 17:21:17 +02:00
|
|
|
showInvalidJoplinCloudCredential: state.settings['sync.target'] === 10 && state.mustAuthenticate,
|
2024-04-10 16:31:04 +02:00
|
|
|
};
|
|
|
|
})(WarningBannerComponent);
|