fix: excess dialog

This commit is contained in:
Ahmed Bouhuolia
2024-07-25 11:01:26 +02:00
parent daf1cd38c0
commit b590d2cb03
3 changed files with 51 additions and 17 deletions

View File

@@ -4,9 +4,9 @@ export const ACCOUNT_TYPE = {
BANK: 'bank', BANK: 'bank',
ACCOUNTS_RECEIVABLE: 'accounts-receivable', ACCOUNTS_RECEIVABLE: 'accounts-receivable',
INVENTORY: 'inventory', INVENTORY: 'inventory',
OTHER_CURRENT_ASSET: 'other-ACCOUNT_PARENT_TYPE.CURRENT_ASSET', OTHER_CURRENT_ASSET: 'other-current-asset',
FIXED_ASSET: 'fixed-asset', FIXED_ASSET: 'fixed-asset',
NON_CURRENT_ASSET: 'non-ACCOUNT_PARENT_TYPE.CURRENT_ASSET', NON_CURRENT_ASSET: 'non-current-asset',
ACCOUNTS_PAYABLE: 'accounts-payable', ACCOUNTS_PAYABLE: 'accounts-payable',
CREDIT_CARD: 'credit-card', CREDIT_CARD: 'credit-card',

View File

@@ -1,12 +1,14 @@
// @ts-nocheck // @ts-nocheck
import * as R from 'ramda'; import * as R from 'ramda';
import * as Yup from 'yup'; import * as Yup from 'yup';
import { useMemo } from 'react'; import React, { useMemo } from 'react';
import { Button, Classes, Intent } from '@blueprintjs/core'; import { Button, Classes, Intent } from '@blueprintjs/core';
import { Form, Formik, FormikHelpers, useFormikContext } from 'formik'; import { Form, Formik, FormikHelpers, useFormikContext } from 'formik';
import { AccountsSelect, FFormGroup } from '@/components'; import { AccountsSelect, FFormGroup, FormatNumber } from '@/components';
import { usePaymentMadeFormContext } from '../../PaymentMadeFormProvider'; import { usePaymentMadeFormContext } from '../../PaymentMadeFormProvider';
import withDialogActions from '@/containers/Dialog/withDialogActions'; import withDialogActions from '@/containers/Dialog/withDialogActions';
import { ACCOUNT_TYPE } from '@/constants';
import { usePaymentMadeExcessAmount } from '../../utils';
interface ExcessPaymentValues { interface ExcessPaymentValues {
accountId: string; accountId: string;
@@ -20,15 +22,17 @@ const Schema = Yup.object().shape({
accountId: Yup.number().required(), accountId: Yup.number().required(),
}); });
const DEFAULT_ACCOUNT_SLUG = 'depreciation-expense'; const DEFAULT_ACCOUNT_SLUG = 'prepaid-expenses';
function ExcessPaymentDialogContentRoot({ dialogName, closeDialog }) { function ExcessPaymentDialogContentRoot({ dialogName, closeDialog }) {
const { const {
setFieldValue, setFieldValue,
submitForm, submitForm,
values: { currency_code: currencyCode },
} = useFormikContext(); } = useFormikContext();
const { setIsExcessConfirmed } = usePaymentMadeFormContext(); const { setIsExcessConfirmed } = usePaymentMadeFormContext();
// Handles the form submitting.
const handleSubmit = ( const handleSubmit = (
values: ExcessPaymentValues, values: ExcessPaymentValues,
{ setSubmitting }: FormikHelpers<ExcessPaymentValues>, { setSubmitting }: FormikHelpers<ExcessPaymentValues>,
@@ -42,13 +46,15 @@ function ExcessPaymentDialogContentRoot({ dialogName, closeDialog }) {
closeDialog(dialogName); closeDialog(dialogName);
}); });
}; };
// Handle close button click. // Handle close button click.
const handleCloseBtn = () => { const handleCloseBtn = () => {
closeDialog(dialogName); closeDialog(dialogName);
}; };
// Retrieves the default excess account id.
const defaultAccountId = useDefaultExcessPaymentDeposit(); const defaultAccountId = useDefaultExcessPaymentDeposit();
const excessAmount = usePaymentMadeExcessAmount();
return ( return (
<Formik <Formik
initialValues={{ initialValues={{
@@ -59,7 +65,12 @@ function ExcessPaymentDialogContentRoot({ dialogName, closeDialog }) {
onSubmit={handleSubmit} onSubmit={handleSubmit}
> >
<Form> <Form>
<ExcessPaymentDialogContentForm onClose={handleCloseBtn} /> <ExcessPaymentDialogContentForm
excessAmount={
<FormatNumber value={excessAmount} currency={currencyCode} />
}
onClose={handleCloseBtn}
/>
</Form> </Form>
</Formik> </Formik>
); );
@@ -70,10 +81,12 @@ export const ExcessPaymentDialogContent = R.compose(withDialogActions)(
); );
interface ExcessPaymentDialogContentFormProps { interface ExcessPaymentDialogContentFormProps {
excessAmount: string | number | React.ReactNode;
onClose?: () => void; onClose?: () => void;
} }
function ExcessPaymentDialogContentForm({ function ExcessPaymentDialogContentForm({
excessAmount,
onClose, onClose,
}: ExcessPaymentDialogContentFormProps) { }: ExcessPaymentDialogContentFormProps) {
const { submitForm, isSubmitting } = useFormikContext(); const { submitForm, isSubmitting } = useFormikContext();
@@ -85,19 +98,26 @@ function ExcessPaymentDialogContentForm({
return ( return (
<> <>
<div className={Classes.DIALOG_BODY}> <div className={Classes.DIALOG_BODY}>
<p> <p style={{ marginBottom: 20 }}>
Would you like to record the excess amount of $1000 as advanced Would you like to record the excess amount of{' '}
payment from the customer. <strong>{excessAmount}</strong> as advanced payment from the customer.
</p> </p>
<FFormGroup <FFormGroup
name={'accountId'} name={'accountId'}
label={'The excessed amount will be deposited in the'} label={'The excessed amount will be deposited in the'}
helperText={
'Only other current asset and non current asset accounts will show.'
}
> >
<AccountsSelect <AccountsSelect
name={'accountId'} name={'accountId'}
items={accounts} items={accounts}
buttonProps={{ small: true }} buttonProps={{ small: true }}
filterByTypes={[
ACCOUNT_TYPE.OTHER_CURRENT_ASSET,
ACCOUNT_TYPE.NON_CURRENT_ASSET,
]}
/> />
</FFormGroup> </FFormGroup>
</div> </div>
@@ -109,7 +129,7 @@ function ExcessPaymentDialogContentForm({
loading={isSubmitting} loading={isSubmitting}
onClick={() => submitForm()} onClick={() => submitForm()}
> >
Continue to Payment Save Payment
</Button> </Button>
<Button onClick={handleCloseBtn}>Cancel</Button> <Button onClick={handleCloseBtn}>Cancel</Button>
</div> </div>

View File

@@ -4,10 +4,11 @@ import * as Yup from 'yup';
import * as R from 'ramda'; import * as R from 'ramda';
import { Button, Classes, Intent } from '@blueprintjs/core'; import { Button, Classes, Intent } from '@blueprintjs/core';
import { Form, Formik, FormikHelpers, useFormikContext } from 'formik'; import { Form, Formik, FormikHelpers, useFormikContext } from 'formik';
import { AccountsSelect, FFormGroup } from '@/components'; import { AccountsSelect, FFormGroup, FormatNumber } from '@/components';
import { usePaymentReceiveFormContext } from '../../PaymentReceiveFormProvider'; import { usePaymentReceiveFormContext } from '../../PaymentReceiveFormProvider';
import withDialogActions from '@/containers/Dialog/withDialogActions'; import withDialogActions from '@/containers/Dialog/withDialogActions';
import { usePaymentReceivedTotalExceededAmount } from '../../utils'; import { usePaymentReceivedTotalExceededAmount } from '../../utils';
import { ACCOUNT_TYPE } from '@/constants';
interface ExcessPaymentValues { interface ExcessPaymentValues {
accountId: string; accountId: string;
@@ -21,10 +22,14 @@ const Schema = Yup.object().shape({
accountId: Yup.number().required(), accountId: Yup.number().required(),
}); });
const DEFAULT_ACCOUNT_SLUG = 'depreciation-expense'; const DEFAULT_ACCOUNT_SLUG = 'unearned-revenue';
export function ExcessPaymentDialogContentRoot({ dialogName, closeDialog }) { export function ExcessPaymentDialogContentRoot({ dialogName, closeDialog }) {
const { setFieldValue, submitForm } = useFormikContext(); const {
setFieldValue,
submitForm,
values: { currency_code: currencyCode },
} = useFormikContext();
const { setIsExcessConfirmed } = usePaymentReceiveFormContext(); const { setIsExcessConfirmed } = usePaymentReceiveFormContext();
const initialAccountId = useDefaultExcessPaymentDeposit(); const initialAccountId = useDefaultExcessPaymentDeposit();
const exceededAmount = usePaymentReceivedTotalExceededAmount(); const exceededAmount = usePaymentReceivedTotalExceededAmount();
@@ -57,7 +62,9 @@ export function ExcessPaymentDialogContentRoot({ dialogName, closeDialog }) {
> >
<Form> <Form>
<ExcessPaymentDialogContentForm <ExcessPaymentDialogContentForm
exceededAmount={exceededAmount} exceededAmount={
<FormatNumber value={exceededAmount} currency={currencyCode} />
}
onClose={handleClose} onClose={handleClose}
/> />
</Form> </Form>
@@ -80,7 +87,7 @@ function ExcessPaymentDialogContentForm({ onClose, exceededAmount }) {
return ( return (
<> <>
<div className={Classes.DIALOG_BODY}> <div className={Classes.DIALOG_BODY}>
<p> <p style={{ marginBottom: 20 }}>
Would you like to record the excess amount of{' '} Would you like to record the excess amount of{' '}
<strong>{exceededAmount}</strong> as advanced payment from the <strong>{exceededAmount}</strong> as advanced payment from the
customer. customer.
@@ -89,11 +96,18 @@ function ExcessPaymentDialogContentForm({ onClose, exceededAmount }) {
<FFormGroup <FFormGroup
name={'accountId'} name={'accountId'}
label={'The excessed amount will be deposited in the'} label={'The excessed amount will be deposited in the'}
helperText={
'Only other other current liability and non current liability accounts will show.'
}
> >
<AccountsSelect <AccountsSelect
name={'accountId'} name={'accountId'}
items={accounts} items={accounts}
buttonProps={{ small: true }} buttonProps={{ small: true }}
filterByTypes={[
ACCOUNT_TYPE.OTHER_CURRENT_LIABILITY,
ACCOUNT_TYPE.NON_CURRENT_LIABILITY,
]}
/> />
</FFormGroup> </FFormGroup>
</div> </div>
@@ -106,7 +120,7 @@ function ExcessPaymentDialogContentForm({ onClose, exceededAmount }) {
disabled={isSubmitting} disabled={isSubmitting}
onClick={() => submitForm()} onClick={() => submitForm()}
> >
Continue to Payment Save Payment
</Button> </Button>
<Button onClick={handleCloseBtn}>Cancel</Button> <Button onClick={handleCloseBtn}>Cancel</Button>
</div> </div>