Skip to content

Commit

Permalink
fixup! 4. Contact Row - Add/Edit/Delete pledge
Browse files Browse the repository at this point in the history
  • Loading branch information
dr-bizz committed Aug 28, 2024
1 parent 26cdd9d commit 0ae23c5
Showing 1 changed file with 9 additions and 24 deletions.
33 changes: 9 additions & 24 deletions src/components/Tool/Appeal/Modals/PledgeModal/PledgeModal.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React, { ReactElement } from 'react';
import {
Alert,
DialogActions,
DialogContent,
FormControl,
Expand All @@ -8,6 +9,7 @@ import {
MenuItem,
Select,
Theme,
Typography,
} from '@mui/material';
import { Box, useMediaQuery } from '@mui/system';
import { FastField, FieldProps, Formik } from 'formik';
Expand All @@ -20,7 +22,6 @@ import {
FormTextField,
LogFormLabel,
} from 'src/components/Layouts/Primary/TopBar/Items/AddMenu/Items/AddDonation/StyledComponents';
import { ContactsAutocomplete } from 'src/components/Task/Modal/Form/Inputs/ContactsAutocomplete/ContactsAutocomplete';
import { CustomDateField } from 'src/components/common/DateTimePickers/CustomDateField';
import {
CancelButton,
Expand All @@ -41,22 +42,13 @@ import {
useUpdateAccountListPledgeMutation,
} from './ContactPledge.generated';

export type CreatePledgeFormikSchema = {
contactId: string;
amount: number;
amountCurrency: string;
expectedDate: DateTime<true | false>;
status: string;
};

interface PledgeModalProps {
handleClose: () => void;
contact: AppealContactInfoFragment;
pledge?: AppealContactInfoFragment['pledges'][0];
}

const CreatePledgeSchema = yup.object({
contactId: yup.string().required(),
amount: yup
.number()
.typeError(i18n.t('Amount must be a valid number'))
Expand Down Expand Up @@ -167,14 +159,12 @@ export const PledgeModal: React.FC<PledgeModalProps> = ({

const initialValues = pledge
? {
contactId: contact.id,
amount: pledge.amount,
amountCurrency: pledge.amountCurrency ?? 'USD',
expectedDate: DateTime.fromISO(pledge.expectedDate),
status: pledge.status ?? PledgeStatusEnum.NotReceived,
}
: {
contactId: contact.id,
amount: 0,
amountCurrency: 'USD',
expectedDate: DateTime.local().startOf('day'),
Expand All @@ -194,7 +184,6 @@ export const PledgeModal: React.FC<PledgeModalProps> = ({
onSubmit={onSubmit}
>
{({
values: { contactId },
setFieldValue,
handleSubmit,
isSubmitting,
Expand All @@ -205,14 +194,11 @@ export const PledgeModal: React.FC<PledgeModalProps> = ({
<form onSubmit={handleSubmit}>
<DialogContent>
<Grid item>
<ContactsAutocomplete
accountListId={accountListId ?? ''}
value={[contactId]}
onChange={(contactId) => {
setFieldValue('contactId', contactId);
}}
disabled={true}
/>
<Alert severity="info" sx={{ marginBottom: 1 }}>
<Typography>
{t('You are adding a commitment for')} <b>{contact.name}</b>
</Typography>
</Alert>
</Grid>

{/* Amount and Currency Row */}
Expand Down Expand Up @@ -384,14 +370,13 @@ export const PledgeModal: React.FC<PledgeModalProps> = ({
}}
error={!!errors.status && touched.status}
>
<MenuItem value={''} disabled></MenuItem>
<MenuItem value={PledgeStatusEnum.NotReceived}>
Committed
{t('Committed')}
</MenuItem>
<MenuItem
value={PledgeStatusEnum.ReceivedNotProcessed}
>
Received
{t('Received')}
</MenuItem>
</Select>
</Box>
Expand Down

0 comments on commit 0ae23c5

Please sign in to comment.