Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Target Date Field added to withdrawals forms. #1611

Merged
merged 5 commits into from
Oct 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/components/admin/transfers/CreateForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ export default function CreateForm({ campaigns }: Props) {
}),
reason: yup.string().trim().min(1).max(300).required(),
documentId: yup.string().uuid().notRequired().nullable(),
targetDate: yup.date().min(new Date(), 'Date is invalid.').notRequired().nullable(),
targetDate: yup.date().required(),
approvedById: yup.string().uuid().notRequired().nullable(),
sourceVaultId: yup.string().uuid().required(),
sourceCampaignId: yup.string().uuid().required(),
Expand All @@ -101,7 +101,7 @@ export default function CreateForm({ campaigns }: Props) {
amount: toMoney(values.amount),
reason: values.reason,
documentId: values.documentId ? values.documentId : null,
targetDate: values.targetDate ? new Date(values.targetDate) : null,
targetDate: values.targetDate,
approvedById: values.approvedById ? values.approvedById : null,
sourceCampaignId: values.sourceCampaignId,
sourceVaultId: values.sourceVaultId,
Expand Down
6 changes: 3 additions & 3 deletions src/components/admin/transfers/EditForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ const validationSchema: yup.SchemaOf<TransferData> = yup.object().shape({
amount: yup.number().positive('Amount must be a positive number.').required(),
reason: yup.string().trim().min(1).max(300).required(),
documentId: yup.string().uuid().notRequired().nullable(),
targetDate: yup.date().min(new Date(), 'Date is invalid.').notRequired().nullable(),
targetDate: yup.date().required(),
approvedById: yup.string().uuid().notRequired().nullable(),
sourceVaultId: yup.string().uuid().required(),
sourceCampaignId: yup.string().uuid().required(),
Expand Down Expand Up @@ -97,7 +97,7 @@ export default function EditForm({ transfer, campaigns, id }: Props) {
amount: toMoney(values.amount),
reason: values.reason,
documentId: values.documentId ? values.documentId : null,
targetDate: values.targetDate ? new Date(values.targetDate) : null,
targetDate: values.targetDate,
approvedById: values.approvedById ? values.approvedById : null,
sourceCampaignId: values.sourceCampaignId,
sourceVaultId: values.sourceVaultId,
Expand Down Expand Up @@ -130,7 +130,7 @@ export default function EditForm({ transfer, campaigns, id }: Props) {
<FormTextField disabled type="number" label={t('amount')} name="amount" />
</Grid>
<Grid item xs={12}>
<SelectDate label={t('targetDate')} name="targetDate" />
<SelectDate name="targetDate" />
</Grid>

<Grid item xs={12}>
Expand Down
7 changes: 7 additions & 0 deletions src/components/admin/withdrawals/CreateForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { AxiosError, AxiosResponse } from 'axios'
import * as yup from 'yup'
import { Box, Button, Grid, Typography } from '@mui/material'

import SelectDate from './custom/SelectDate'
import { WithdrawalData, WithdrawalInput, WithdrawalResponse } from 'gql/withdrawals'
import { routes } from 'common/routes'
import { ApiErrors } from 'service/apiErrors'
Expand Down Expand Up @@ -57,6 +58,7 @@ export default function CreateForm() {
otherwise: yup.number().positive().integer().required(),
}),
reason: yup.string().trim().min(1).max(300).required(),
targetDate: yup.date().required(),
currency: yup.string().oneOf(Object.values(Currency)).required(),
sourceVaultId: yup.string().uuid().required(),
sourceCampaignId: yup.string().uuid().required(),
Expand All @@ -74,6 +76,7 @@ export default function CreateForm() {
sourceCampaignId: '',
bankAccountId: '',
documentId: uuidv4(), //this will be the id of the uploaded doc when attachments are implemented
targetDate: '',
approvedById: '',
}

Expand Down Expand Up @@ -102,6 +105,7 @@ export default function CreateForm() {
sourceCampaignId: values.sourceCampaignId,
bankAccountId: values.bankAccountId,
documentId: values.documentId,
targetDate: values.targetDate,
approvedById: values.approvedById,
}
mutation.mutate(data)
Expand Down Expand Up @@ -182,6 +186,9 @@ export default function CreateForm() {
<Grid item xs={12}>
<FormTextField type="text" label={t('reason')} name="reason" autoComplete="reason" />
</Grid>
<Grid item xs={12}>
<SelectDate name="targetDate" />
</Grid>

<Grid item xs={12}>
<BankAccountSelect />
Expand Down
14 changes: 14 additions & 0 deletions src/components/admin/withdrawals/EditForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,14 @@ import { Currency } from 'gql/currency'
import { fromMoney, toMoney } from 'common/util/money'
import { useVaultsList } from 'common/hooks/vaults'
import FormSelectField from 'components/common/form/FormSelectField'
import SelectDate from './custom/SelectDate'

const dateParser = (date: Date | undefined) => {
if (date) {
return date.toString().slice(0, 10)
}
return undefined
}

const validationSchema: yup.SchemaOf<WithdrawalData> = yup
.object()
Expand All @@ -46,6 +54,7 @@ const validationSchema: yup.SchemaOf<WithdrawalData> = yup
sourceCampaignId: yup.string().uuid().required(),
bankAccountId: yup.string().uuid().required(),
documentId: yup.string().uuid().required(),
targetDate: yup.date().required(),
approvedById: yup.string().uuid().required(),
})

Expand All @@ -71,6 +80,7 @@ export default function EditForm() {
bankAccountId: data?.bankAccountId,
documentId: data?.documentId,
approvedById: data?.approvedById,
targetDate: dateParser(data?.targetDate) || '',
}

const mutation = useMutation<
Expand All @@ -95,6 +105,7 @@ export default function EditForm() {
reason: values.reason,
sourceVaultId: values.sourceVaultId,
sourceCampaignId: values.sourceCampaignId,
targetDate: values.targetDate,
bankAccountId: values.bankAccountId,
documentId: values.documentId,
approvedById: values.approvedById,
Expand Down Expand Up @@ -158,6 +169,9 @@ export default function EditForm() {
<Grid item xs={12}>
<BankAccountSelect disabled={initialValues.status === WithdrawalStatus.succeeded} />
</Grid>
<Grid item xs={12}>
<SelectDate name="targetDate" />
</Grid>
<Grid item xs={12}>
<FormTextField
type="string"
Expand Down
35 changes: 35 additions & 0 deletions src/components/admin/withdrawals/custom/SelectDate.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import React from 'react'
import { useField } from 'formik'
import { useTranslation } from 'next-i18next'

import { TextFieldProps } from '@mui/material'

import { translateError } from 'common/form/useForm'
import { TranslatableField } from 'common/form/validation'
import FormTextField from 'components/common/form/FormTextField'

type Props = {
name: string
} & TextFieldProps

export default function SelectDate({ name, ...textFieldProps }: Props) {
const { t } = useTranslation('withdrawals')

const [field, meta] = useField(name)

const helperText = meta.touched ? translateError(meta.error as TranslatableField, t) : ''

return (
<FormTextField
{...textFieldProps}
{...field}
type="date"
variant="outlined"
fullWidth
InputLabelProps={{ shrink: true }}
error={Boolean(meta.error) && Boolean(meta.touched)}
label={t('targetDate')}
helperText={helperText}
/>
)
}
6 changes: 3 additions & 3 deletions src/gql/transfer.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export type TransferInput = {
amount: number
reason: string
documentId?: UUID | string | null
targetDate?: Date | string | null
targetDate: Date | string
approvedById?: string | null
sourceCampaignId: string
sourceVaultId: string
Expand All @@ -25,7 +25,7 @@ export type TransferData = {
amount: number | undefined
reason: string | undefined
documentId?: UUID | string | null
targetDate?: Date | string | null
targetDate: Date | string
approvedById?: UUID | string | null
sourceCampaignId: UUID | string | undefined
sourceVaultId: UUID | string | undefined
Expand All @@ -40,7 +40,7 @@ export type TransferResponse = {
amount: number
reason: string
documentId: string | undefined
targetDate: Date | undefined
targetDate: Date
approvedBy: PersonResponse | undefined
sourceCampaign: CampaignResponse
sourceVault: VaultResponse
Expand Down
5 changes: 5 additions & 0 deletions src/gql/withdrawals.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export type WithdrawalResponse = {
amount: number
reason: string
documentId: UUID
targetDate: Date
approvedBy: Person
bankAccount: Record<string, unknown>
sourceCampaign: Record<string, unknown>
Expand All @@ -21,6 +22,7 @@ export type WithdrawalResponse2 = {
amount: number
reason: string
documentId: UUID
targetDate: Date
approvedBy: string
bankAccount: string
sourceCampaign: string
Expand All @@ -33,6 +35,7 @@ export type WithdrawalInput = {
amountAvailable: number
reason: string | undefined
documentId?: UUID | undefined
targetDate: Date | string
approvedById?: UUID | undefined
bankAccountId?: UUID | undefined
sourceCampaignId?: UUID | undefined
Expand All @@ -45,6 +48,7 @@ export type WithdrawalData = {
amount: number | undefined
reason: string | undefined
documentId?: string | undefined
targetDate: Date | string
approvedById?: string | undefined
bankAccountId?: string | undefined
sourceCampaignId?: string | undefined
Expand All @@ -58,6 +62,7 @@ export type WithdrawalEditResponse = {
amount: number
reason: string
documentId: UUID
targetDate: Date
approvedById: UUID
bankAccountId: UUID
sourceCampaignId: UUID
Expand Down
Loading