From ea06ae32fb759e477a967fa06d05f65c91f68761 Mon Sep 17 00:00:00 2001 From: Gustav Larsson Date: Wed, 5 Mar 2025 14:11:08 +0100 Subject: [PATCH] Fix(Expense form): Account balance payout method fixes (#11065) * Fix(Expense form): Account balance payout method fixes * update graphql * Fix merge * Remove unused code * Set newPayoutMethodType options for non logged in user --------- Co-authored-by: Henrique --- components/expenses/EditExpenseDialog.tsx | 24 ++++++++++---- .../submit-expense/SubmitExpenseFlow.tsx | 11 +++++-- .../form/PayoutMethodSection.tsx | 17 +++++----- components/submit-expense/useExpenseForm.ts | 33 ++++++++++++++++++- lib/graphql/types/v2/gql.ts | 4 +-- lib/graphql/types/v2/graphql.ts | 2 +- 6 files changed, 69 insertions(+), 22 deletions(-) diff --git a/components/expenses/EditExpenseDialog.tsx b/components/expenses/EditExpenseDialog.tsx index 60286d14a88..e9ab30eeb68 100644 --- a/components/expenses/EditExpenseDialog.tsx +++ b/components/expenses/EditExpenseDialog.tsx @@ -9,7 +9,7 @@ import { z } from 'zod'; import { i18nGraphqlException } from '../../lib/errors'; import { API_V2_CONTEXT } from '../../lib/graphql/helpers'; -import type { Currency, CurrencyExchangeRateInput } from '../../lib/graphql/types/v2/graphql'; +import { type Currency, type CurrencyExchangeRateInput, PayoutMethodType } from '../../lib/graphql/types/v2/graphql'; import { cn } from '../../lib/utils'; import type { Expense } from '@/lib/graphql/types/v2/schema'; @@ -87,9 +87,14 @@ const EditPayee = ({ expense, onSubmit }) => { payoutMethod: !values.payoutMethodId || values.payoutMethodId === '__newPayoutMethod' ? { ...values.newPayoutMethod, isSaved: false } - : { - id: values.payoutMethodId, - }, + : values.payoutMethodId === '__newAccountBalancePayoutMethod' + ? { + type: PayoutMethodType.ACCOUNT_BALANCE, + data: {}, + } + : { + id: values.payoutMethodId, + }, }), }; return onSubmit(editValues); @@ -167,9 +172,14 @@ const EditPayoutMethod = ({ expense, onSubmit }) => { payoutMethod: !values.payoutMethodId || values.payoutMethodId === '__newPayoutMethod' ? { ...values.newPayoutMethod, isSaved: false } - : { - id: values.payoutMethodId, - }, + : values.payoutMethodId === '__newAccountBalancePayoutMethod' + ? { + type: PayoutMethodType.ACCOUNT_BALANCE, + data: {}, + } + : { + id: values.payoutMethodId, + }, payee: { slug: formOptions.payee?.slug, }, diff --git a/components/submit-expense/SubmitExpenseFlow.tsx b/components/submit-expense/SubmitExpenseFlow.tsx index cd1c15e190d..28f262773c8 100644 --- a/components/submit-expense/SubmitExpenseFlow.tsx +++ b/components/submit-expense/SubmitExpenseFlow.tsx @@ -182,9 +182,14 @@ export function SubmitExpenseFlow(props: SubmitExpenseFlowProps) { payoutMethod: !values.payoutMethodId || values.payoutMethodId === '__newPayoutMethod' ? { ...values.newPayoutMethod, isSaved: false } - : { - id: values.payoutMethodId, - }, + : values.payoutMethodId === '__newAccountBalancePayoutMethod' + ? { + type: PayoutMethodType.ACCOUNT_BALANCE, + data: {}, + } + : { + id: values.payoutMethodId, + }, type: values.expenseTypeOption, accountingCategory: values.accountingCategoryId ? { diff --git a/components/submit-expense/form/PayoutMethodSection.tsx b/components/submit-expense/form/PayoutMethodSection.tsx index d9c483dd42b..2c380e00b4f 100644 --- a/components/submit-expense/form/PayoutMethodSection.tsx +++ b/components/submit-expense/form/PayoutMethodSection.tsx @@ -50,6 +50,7 @@ function getFormProps(form: ExpenseForm) { ...pick(form.options, [ 'payee', 'payoutMethods', + 'newPayoutMethodTypes', 'recentlySubmittedExpenses', 'isAdminOfPayee', 'loggedInAccount', @@ -198,7 +199,7 @@ export const PayoutMethodFormContent = memoWithGetFormProps(function PayoutMetho )} - {!(isLoading || isLoadingPayee) && !isVendor && ( + {!(isLoading || isLoadingPayee) && !isVendor && props.newPayoutMethodTypes?.length > 0 && ( - props.supportedPayoutMethods.map(m => ({ + props.newPayoutMethodTypes.map(m => ({ value: m, label: intl.formatMessage(I18nPayoutMethodLabels[m]), })), - [intl, props.supportedPayoutMethods], + [intl, props.newPayoutMethodTypes], ); const onPayoutMethodTypeChange = React.useCallback( @@ -358,7 +358,7 @@ const NewPayoutMethodOption = memoWithGetFormProps(function NewPayoutMethodOptio )} @@ -459,6 +459,7 @@ export const PayoutMethodRadioGroupItem = function PayoutMethodRadioGroupItem(pr const intl = useIntl(); const { toast } = useToast(); + const isEditable = props.payoutMethod.type !== PayoutMethodType.ACCOUNT_BALANCE && props.isEditable; const isMissingCurrency = isEmpty(props.payoutMethod.data?.currency); const isLegalNameFuzzyMatched = React.useMemo(() => { const accountHolderName: string = props.payoutMethod.data?.accountHolderName ?? ''; @@ -821,7 +822,7 @@ export const PayoutMethodRadioGroupItem = function PayoutMethodRadioGroupItem(pr )} - {!isEditingPayoutMethod && props.isEditable && ( + {!isEditingPayoutMethod && isEditable && (
{!props.archived && props.isChecked && (