mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-02-17 23:44:39 -05:00
Added "Remove" button to "Edit recommendation" modal
refs https://github.com/TryGhost/Product/issues/3899
This commit is contained in:
parent
6822c6db24
commit
a66d811236
1 changed files with 36 additions and 1 deletions
|
@ -1,10 +1,11 @@
|
||||||
|
import ConfirmationModal from '../../../../admin-x-ds/global/modal/ConfirmationModal';
|
||||||
import Modal from '../../../../admin-x-ds/global/modal/Modal';
|
import Modal from '../../../../admin-x-ds/global/modal/Modal';
|
||||||
import NiceModal, {useModal} from '@ebay/nice-modal-react';
|
import NiceModal, {useModal} from '@ebay/nice-modal-react';
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import RecommendationReasonForm from './RecommendationReasonForm';
|
import RecommendationReasonForm from './RecommendationReasonForm';
|
||||||
import useForm from '../../../../hooks/useForm';
|
import useForm from '../../../../hooks/useForm';
|
||||||
import useRouting from '../../../../hooks/useRouting';
|
import useRouting from '../../../../hooks/useRouting';
|
||||||
import {Recommendation, useBrowseRecommendations, useEditRecommendation} from '../../../../api/recommendations';
|
import {Recommendation, useBrowseRecommendations, useDeleteRecommendation, useEditRecommendation} from '../../../../api/recommendations';
|
||||||
import {RoutingModalProps} from '../../../providers/RoutingProvider';
|
import {RoutingModalProps} from '../../../providers/RoutingProvider';
|
||||||
import {showToast} from '../../../../admin-x-ds/global/Toast';
|
import {showToast} from '../../../../admin-x-ds/global/Toast';
|
||||||
import {toast} from 'react-hot-toast';
|
import {toast} from 'react-hot-toast';
|
||||||
|
@ -18,6 +19,7 @@ const EditRecommendationModalConfirm: React.FC<AddRecommendationModalProps> = ({
|
||||||
const modal = useModal();
|
const modal = useModal();
|
||||||
const {updateRoute} = useRouting();
|
const {updateRoute} = useRouting();
|
||||||
const {mutateAsync: editRecommendation} = useEditRecommendation();
|
const {mutateAsync: editRecommendation} = useEditRecommendation();
|
||||||
|
const {mutateAsync: deleteRecommendation} = useDeleteRecommendation();
|
||||||
|
|
||||||
const {formState, updateForm, handleSave, saveState, errors} = useForm({
|
const {formState, updateForm, handleSave, saveState, errors} = useForm({
|
||||||
initialState: {
|
initialState: {
|
||||||
|
@ -45,6 +47,38 @@ const EditRecommendationModalConfirm: React.FC<AddRecommendationModalProps> = ({
|
||||||
okLabel = 'Saved';
|
okLabel = 'Saved';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let leftButtonProps = {
|
||||||
|
label: 'Remove recommendation',
|
||||||
|
link: true,
|
||||||
|
color: 'red' as const,
|
||||||
|
size: 'sm' as const,
|
||||||
|
onClick: () => {
|
||||||
|
modal.remove();
|
||||||
|
NiceModal.show(ConfirmationModal, {
|
||||||
|
title: 'Remove recommendation',
|
||||||
|
prompt: <>
|
||||||
|
<p>Your recommendation <strong>{recommendation.title}</strong> will no longer be visible to your audience.</p>
|
||||||
|
</>,
|
||||||
|
okLabel: 'Remove',
|
||||||
|
onOk: async (deleteModal) => {
|
||||||
|
try {
|
||||||
|
await deleteRecommendation(recommendation);
|
||||||
|
deleteModal?.remove();
|
||||||
|
showToast({
|
||||||
|
message: 'Successfully removed the recommendation',
|
||||||
|
type: 'success'
|
||||||
|
});
|
||||||
|
} catch (_) {
|
||||||
|
showToast({
|
||||||
|
message: 'Failed to remove the recommendation. Please try again later.',
|
||||||
|
type: 'error'
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
return <Modal
|
return <Modal
|
||||||
afterClose={() => {
|
afterClose={() => {
|
||||||
// Closed without saving: reset route
|
// Closed without saving: reset route
|
||||||
|
@ -53,6 +87,7 @@ const EditRecommendationModalConfirm: React.FC<AddRecommendationModalProps> = ({
|
||||||
animate={animate ?? true}
|
animate={animate ?? true}
|
||||||
backDropClick={false}
|
backDropClick={false}
|
||||||
cancelLabel={'Cancel'}
|
cancelLabel={'Cancel'}
|
||||||
|
leftButtonProps={leftButtonProps}
|
||||||
okColor='black'
|
okColor='black'
|
||||||
okLabel={okLabel}
|
okLabel={okLabel}
|
||||||
size='sm'
|
size='sm'
|
||||||
|
|
Loading…
Add table
Reference in a new issue