diff --git a/src/components/Tool/Appeal/AddAppealForm.tsx b/src/components/Tool/Appeal/AddAppealForm.tsx index c8e0f847f..0c2a860f1 100644 --- a/src/components/Tool/Appeal/AddAppealForm.tsx +++ b/src/components/Tool/Appeal/AddAppealForm.tsx @@ -23,6 +23,10 @@ import { useTranslation } from 'react-i18next'; import { makeStyles } from 'tss-react/mui'; import * as yup from 'yup'; import { useContactFiltersQuery } from 'pages/accountLists/[accountListId]/contacts/Contacts.generated'; +import { + GetAppealsDocument, + GetAppealsQuery, +} from 'pages/accountLists/[accountListId]/tools/GetAppeals.generated'; import { MultiselectFilter } from 'src/graphql/types.generated'; import i18n from 'src/lib/i18n'; import theme from '../../../theme'; @@ -46,14 +50,6 @@ const useStyles = makeStyles()((theme: Theme) => ({ width: '150px', color: 'white', }, - blueBox: { - border: '1px solid', - borderColor: theme.palette.mpdxBlue.main, - borderRadius: 5, - backgroundColor: theme.palette.cruGrayLight.main, - color: theme.palette.mpdxBlue.main, - padding: 10, - }, selectAll: { color: theme.palette.mpdxBlue.main, marginLeft: 5, @@ -159,7 +155,7 @@ const AddAppealForm: React.FC = ({ accountListId }) => { } }, [contactFilterGroups]); - const onSubmit = async (props: FormAttributes) => { + const onSubmit = async (props: FormAttributes, resetForm: () => void) => { const attributes = { name: props.name, amount: calculateGoal( @@ -174,10 +170,30 @@ const AddAppealForm: React.FC = ({ accountListId }) => { accountListId, attributes, }, + update: (cache, result) => { + const query = { + query: GetAppealsDocument, + variables: { accountListId }, + }; + const dataFromCache = cache.readQuery(query); + if (dataFromCache && result.data?.createAppeal?.appeal) { + const data = { + regularAppeals: { + ...dataFromCache.regularAppeals, + nodes: [ + { ...result.data.createAppeal.appeal }, + ...dataFromCache.regularAppeals.nodes, + ], + }, + }; + cache.writeQuery({ ...query, data }); + } + }, }); enqueueSnackbar(t('Appeal successfully added!'), { variant: 'success', }); + resetForm(); }; const contactTagsList = contactFilterTags?.accountList.contactTagList ?? []; @@ -205,8 +221,6 @@ const AddAppealForm: React.FC = ({ accountListId }) => { title="Add Appeal" style={{ backgroundColor: theme.palette.cruGrayLight.main, - borderBottom: '1px solid', - borderColor: theme.palette.cruGrayMedium.main, }} /> @@ -220,7 +234,9 @@ const AddAppealForm: React.FC = ({ accountListId }) => { tags: [], exclusions: [], }} - onSubmit={onSubmit} + onSubmit={async (values, { resetForm }) => { + await onSubmit(values, resetForm); + }} validationSchema={appealFormSchema} > {({ @@ -257,7 +273,7 @@ const AddAppealForm: React.FC = ({ accountListId }) => { - + = ({ accountListId }) => { /> - + = ({ accountListId }) => { - + = ({ accountListId }) => { /> - + = ({ accountListId }) => { - + = ({ accountListId }) => { /> - + = ({ accountListId }) => { - + = ({ accountListId }) => { - - - {t( - 'You can add contacts to your appeal based on their status and/or tags. You can also add additional contacts individually at a later time.', - )} - - - + + {t( + 'You can add contacts to your appeal based on their status and/or tags. You can also add additional contacts individually at a later time.', + )} + - + {t('Add contacts with the following status(es):')} {!!contactStatuses && ( handleSelectAllStatuses(setFieldValue)} @@ -403,7 +415,6 @@ const AddAppealForm: React.FC = ({ accountListId }) => { {!!contactStatuses && !loadingStatuses && ( = ({ accountListId }) => { - + {t('Add contacts with the following tag(s):')} {!!contactTagsList.length && ( handleSelectAllTags(setFieldValue)} @@ -447,7 +457,6 @@ const AddAppealForm: React.FC = ({ accountListId }) => { {contactTagsList && !loadingTags && ( = ({ accountListId }) => { )} - - {t('Do not add contacts who:')} - + {t('Do not add contacts who:')} - + = ({ accountListId }) => { )} {!loading && ( - + Showing{' '} {(data?.primaryAppeal ? data.primaryAppeal.nodes.length : 0) + diff --git a/src/components/Tool/Appeal/CreateAppeal.graphql b/src/components/Tool/Appeal/CreateAppeal.graphql index 6acfc1dc2..19d24942e 100644 --- a/src/components/Tool/Appeal/CreateAppeal.graphql +++ b/src/components/Tool/Appeal/CreateAppeal.graphql @@ -3,7 +3,7 @@ mutation CreateAppeal($accountListId: ID!, $attributes: AppealCreateInput!) { input: { accountListId: $accountListId, attributes: $attributes } ) { appeal { - id + ...AppealFields } } }