Skip to content

Commit

Permalink
fix: response handling for 'save to files'
Browse files Browse the repository at this point in the history
  • Loading branch information
dhavaldodiya committed Jun 21, 2023
1 parent 9c177b9 commit d9fbb40
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 13 deletions.
5 changes: 5 additions & 0 deletions src/types/details-pannel/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,8 @@ export type PreviewPanelActionsType = {
isMessageView: boolean;
conversation: Conversation;
};

export type CopyToFileResponse = {
status?: string;
value?: Record<string, unknown>;
};
48 changes: 35 additions & 13 deletions src/views/app/detail-panel/preview/attachments-block.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import { StoreProvider } from '../../../../store/redux';
import type {
AttachmentPart,
AttachmentType,
CopyToFileResponse,
MailMessage,
OpenEmlPreviewType
} from '../../../../types';
Expand Down Expand Up @@ -187,15 +188,29 @@ const Attachment: FC<AttachmentType> = ({
part: att.name,
destinationFolderId: nodes[0].id
})
.then(() => {
getBridgedFunctions()?.createSnackbar({
key: `calendar-moved-root`,
replace: true,
type: 'info',
hideButton: true,
label: t('message.snackbar.att_saved', 'Attachment saved in the selected folder'),
autoHideTimeout: 3000
});
.then((res: any) => {
if (!res?.Fault) {
getBridgedFunctions()?.createSnackbar({
key: `mail-moved-root`,
replace: true,
type: 'info',
hideButton: true,
label: t('message.snackbar.att_saved', 'Attachment saved in the selected folder'),
autoHideTimeout: 3000
});
} else {
getBridgedFunctions()?.createSnackbar({
key: `mail-moved-root`,
replace: true,
type: 'warning',
hideButton: true,
label: t(
'message.snackbar.att_err',
'There seems to be a problem when saving, please try again'
),
autoHideTimeout: 3000
});
}
})
.catch(() => {
getBridgedFunctions()?.createSnackbar({
Expand All @@ -211,7 +226,7 @@ const Attachment: FC<AttachmentType> = ({
});
});
},
[att.name, message.id]
[att, message]
);

const isAValidDestination = useCallback((node) => node?.permissions?.can_write_file, []);
Expand Down Expand Up @@ -405,7 +420,11 @@ const Attachment: FC<AttachmentType> = ({
);
};

const copyToFiles = (att: AttachmentPart, message: MailMessage, nodes: any): Promise<any> =>
const copyToFiles = (
att: AttachmentPart,
message: MailMessage,
nodes: any
): Promise<CopyToFileResponse> =>
soapFetch('CopyToFiles', {
_jsns: 'urn:zimbraMail',
mid: message.id,
Expand Down Expand Up @@ -465,8 +484,11 @@ const AttachmentsBlock: FC<{
const confirmAction = useCallback(
(nodes) => {
const promises = map(attachments, (att) => copyToFiles(att, message, nodes));
Promise.allSettled(promises).then((res) => {
const allSuccess = res.length === filter(res, ['status', 'fulfilled'])?.length;
Promise.allSettled(promises).then((res: CopyToFileResponse[]) => {
const isFault = res.length === filter(res, (r) => r?.value?.Fault)?.length;
const allSuccess = isFault
? false
: res.length === filter(res, ['status', 'fulfilled'])?.length;
const allFails = res.length === filter(res, ['status', 'rejected'])?.length;
const type = allSuccess ? 'info' : 'warning';
const label = getLabel({ allSuccess, allFails });
Expand Down

0 comments on commit d9fbb40

Please sign in to comment.