mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-11-24 14:43:08 +03:00
Added recommedation add/remove toasts (#18113)
fixes https://github.com/TryGhost/Product/issues/3844
This commit is contained in:
parent
cb6a8ff6df
commit
908e02c016
@ -97,3 +97,7 @@ export const showToast = ({
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
export const dismissAllToasts = (): void => {
|
||||
toast.dismiss();
|
||||
};
|
||||
|
@ -47,7 +47,13 @@ export const ConfirmationModalContent: React.FC<ConfirmationModalProps> = ({
|
||||
onCancel={onCancel}
|
||||
onOk={async () => {
|
||||
setTaskState('running');
|
||||
await onOk?.(modal);
|
||||
|
||||
try {
|
||||
await onOk?.(modal);
|
||||
} catch (e) {
|
||||
// eslint-disable-next-line no-console
|
||||
console.error('Unhandled Promise Rejection. Make sure you catch errors in your onOk handler.', e);
|
||||
}
|
||||
setTaskState('');
|
||||
}}
|
||||
>
|
||||
|
@ -6,8 +6,7 @@ import RecommendationReasonForm from './RecommendationReasonForm';
|
||||
import useForm from '../../../../hooks/useForm';
|
||||
import useRouting from '../../../../hooks/useRouting';
|
||||
import {EditOrAddRecommendation, useAddRecommendation} from '../../../../api/recommendations';
|
||||
import {showToast} from '../../../../admin-x-ds/global/Toast';
|
||||
import {toast} from 'react-hot-toast';
|
||||
import {dismissAllToasts, showToast} from '../../../../admin-x-ds/global/Toast';
|
||||
|
||||
interface AddRecommendationModalProps {
|
||||
recommendation: EditOrAddRecommendation,
|
||||
@ -26,6 +25,10 @@ const AddRecommendationModalConfirm: React.FC<AddRecommendationModalProps> = ({r
|
||||
onSave: async () => {
|
||||
await addRecommendation(formState);
|
||||
modal.remove();
|
||||
showToast({
|
||||
message: 'Successfully added a recommendation',
|
||||
type: 'success'
|
||||
});
|
||||
updateRoute('recommendations');
|
||||
},
|
||||
onValidate: () => {
|
||||
@ -95,7 +98,7 @@ const AddRecommendationModalConfirm: React.FC<AddRecommendationModalProps> = ({r
|
||||
return;
|
||||
}
|
||||
|
||||
toast.remove();
|
||||
dismissAllToasts();
|
||||
if (await handleSave({force: true})) {
|
||||
// Already handled
|
||||
} else {
|
||||
|
@ -10,6 +10,7 @@ import TableRow from '../../../../admin-x-ds/global/TableRow';
|
||||
import useRouting from '../../../../hooks/useRouting';
|
||||
import {PaginationData} from '../../../../hooks/usePagination';
|
||||
import {Recommendation, useDeleteRecommendation} from '../../../../api/recommendations';
|
||||
import {showToast} from '../../../../admin-x-ds/global/Toast';
|
||||
|
||||
interface RecommendationListProps {
|
||||
recommendations: Recommendation[],
|
||||
@ -31,8 +32,19 @@ const RecommendationItem: React.FC<{recommendation: Recommendation}> = ({recomme
|
||||
</>,
|
||||
okLabel: 'Remove',
|
||||
onOk: async (modal) => {
|
||||
await deleteRecommendation(recommendation);
|
||||
modal?.remove();
|
||||
try {
|
||||
await deleteRecommendation(recommendation);
|
||||
modal?.remove();
|
||||
showToast({
|
||||
message: 'Successfully removed the recommendation',
|
||||
type: 'success'
|
||||
});
|
||||
} catch (_) {
|
||||
showToast({
|
||||
message: 'Failed to remove the recommendation. Please try again later.',
|
||||
type: 'error'
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
}} />
|
||||
|
Loading…
Reference in New Issue
Block a user