From 2333f4217f643fd0f12b7e1b454594ed2d243d88 Mon Sep 17 00:00:00 2001 From: Vasilica Olariu Date: Wed, 18 Jun 2025 09:16:39 +0300 Subject: [PATCH 1/2] PM-1304 - allow admin to update payment description --- .../src/home/tabs/payments/PaymentsTab.tsx | 5 +++ .../components/payment-edit/PaymentEdit.tsx | 36 +++++++++++++++++-- 2 files changed, 39 insertions(+), 2 deletions(-) diff --git a/src/apps/wallet-admin/src/home/tabs/payments/PaymentsTab.tsx b/src/apps/wallet-admin/src/home/tabs/payments/PaymentsTab.tsx index 5fc3bf4ba..ced769e09 100644 --- a/src/apps/wallet-admin/src/home/tabs/payments/PaymentsTab.tsx +++ b/src/apps/wallet-admin/src/home/tabs/payments/PaymentsTab.tsx @@ -78,6 +78,7 @@ const ListView: FC = (props: ListViewProps) => { totalPages: 0, }) const [editState, setEditState] = React.useState<{ + description?: string; grossAmount?: number; releaseDate?: Date; paymentStatus?: string; @@ -93,6 +94,7 @@ const ListView: FC = (props: ListViewProps) => { const handleValueUpdated = useCallback((updates: { auditNote?: string, + description?: string, grossAmount?: number, paymentStatus?: string, releaseDate?: Date, @@ -204,6 +206,7 @@ const ListView: FC = (props: ListViewProps) => { const currentEditState = editStateRef.current // Send to server only the fields that have changed const updateObj = { + description: currentEditState.description !== undefined ? currentEditState.description : undefined, auditNote: currentEditState.auditNote !== undefined ? currentEditState.auditNote : undefined, grossAmount: currentEditState.grossAmount !== undefined ? currentEditState.grossAmount : undefined, paymentStatus: currentEditState.paymentStatus !== undefined ? currentEditState.paymentStatus : undefined, @@ -222,6 +225,7 @@ const ListView: FC = (props: ListViewProps) => { } const updates: { + description?: string auditNote?: string paymentStatus?: 'ON_HOLD_ADMIN' | 'OWED' | 'CANCELLED' releaseDate?: string @@ -232,6 +236,7 @@ const ListView: FC = (props: ListViewProps) => { winningsId: paymentId, } + if (updateObj.description) updates.description = updateObj.description if (paymentStatus) updates.paymentStatus = paymentStatus if (paymentStatus !== 'CANCELLED') { if (updateObj.releaseDate !== undefined) updates.releaseDate = updateObj.releaseDate.toISOString() diff --git a/src/apps/wallet-admin/src/lib/components/payment-edit/PaymentEdit.tsx b/src/apps/wallet-admin/src/lib/components/payment-edit/PaymentEdit.tsx index f1a2a66c6..d06ebe2f6 100644 --- a/src/apps/wallet-admin/src/lib/components/payment-edit/PaymentEdit.tsx +++ b/src/apps/wallet-admin/src/lib/components/payment-edit/PaymentEdit.tsx @@ -18,6 +18,7 @@ interface PaymentEditFormProps { releaseDate, grossAmount, paymentStatus, auditNote, }: { releaseDate?: Date + description?: string grossAmount?: number paymentStatus?: string auditNote?: string @@ -25,6 +26,7 @@ interface PaymentEditFormProps { } const PaymentEdit: React.FC = (props: PaymentEditFormProps) => { + const [description, setDescription] = useState('') const [paymentStatus, setPaymentStatus] = useState('') const [releaseDate, setReleaseDate] = useState(new Date()) const [grossAmount, setGrossAmount] = useState(0) @@ -35,6 +37,7 @@ const PaymentEdit: React.FC = (props: PaymentEditFormProps const initialValues = useMemo(() => ({ auditNote: '', + description: props.payment.description, grossAmount: props.payment.grossAmountNumber, paymentStatus: props.payment.status, releaseDate: props.payment.releaseDateObj, @@ -85,6 +88,15 @@ const PaymentEdit: React.FC = (props: PaymentEditFormProps }) } + break + case 'description': + setDescription(value as string) + if (props.onValueUpdated) { + props.onValueUpdated({ + description: value as string, + }) + } + break case 'releaseDate': setReleaseDate(value as Date) @@ -110,6 +122,7 @@ const PaymentEdit: React.FC = (props: PaymentEditFormProps } useEffect(() => { + setDescription(props.payment.description) setPaymentStatus(props.payment.status) setReleaseDate(props.payment.releaseDateObj) setGrossAmount(props.payment.grossAmountNumber) @@ -117,6 +130,9 @@ const PaymentEdit: React.FC = (props: PaymentEditFormProps useEffect(() => { const valuesToCheck = [{ + key: 'description', + value: description, + }, { key: 'grossPayment', value: grossAmount, }, { @@ -132,7 +148,7 @@ const PaymentEdit: React.FC = (props: PaymentEditFormProps const isDirty = valuesToCheck.some(x => x.value !== initialValues[x.key as keyof typeof initialValues]) setDirty(isDirty) - }, [grossAmount, paymentStatus, releaseDate, auditNote, initialValues]) + }, [description, grossAmount, paymentStatus, releaseDate, auditNote, initialValues]) useEffect(() => { if (props.canSave) { @@ -140,6 +156,9 @@ const PaymentEdit: React.FC = (props: PaymentEditFormProps props.canSave(false) } else { const valuesToCheck = [{ + key: 'description', + value: description, + }, { key: 'grossPayment', value: grossAmount, }, { @@ -154,7 +173,7 @@ const PaymentEdit: React.FC = (props: PaymentEditFormProps props.canSave(haveChange && grossAmountErrorString.length === 0 && auditNote.length > 0) } } - }, [dirty, auditNote, props, grossAmountErrorString.length, grossAmount, paymentStatus, releaseDate, initialValues]) + }, [dirty, auditNote, props, grossAmountErrorString.length, description, grossAmount, paymentStatus, releaseDate, initialValues]) const getLink = (externalId: string): string => `${TOPCODER_URL}/challenges/${externalId}` @@ -208,8 +227,21 @@ const PaymentEdit: React.FC = (props: PaymentEditFormProps error={grossAmountErrorString} value={props.payment.grossAmountNumber.toString()} onChange={e => handleInputChange('grossPayment', parseFloat(e.target.value))} + /> + handleInputChange('description', e.target.value)} /> + Date: Wed, 18 Jun 2025 09:54:33 +0300 Subject: [PATCH 2/2] lint fix --- .../wallet-admin/src/home/tabs/payments/PaymentsTab.tsx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/apps/wallet-admin/src/home/tabs/payments/PaymentsTab.tsx b/src/apps/wallet-admin/src/home/tabs/payments/PaymentsTab.tsx index ced769e09..1158713fa 100644 --- a/src/apps/wallet-admin/src/home/tabs/payments/PaymentsTab.tsx +++ b/src/apps/wallet-admin/src/home/tabs/payments/PaymentsTab.tsx @@ -78,8 +78,8 @@ const ListView: FC = (props: ListViewProps) => { totalPages: 0, }) const [editState, setEditState] = React.useState<{ - description?: string; grossAmount?: number; + description?: string; releaseDate?: Date; paymentStatus?: string; auditNote?: string; @@ -206,8 +206,8 @@ const ListView: FC = (props: ListViewProps) => { const currentEditState = editStateRef.current // Send to server only the fields that have changed const updateObj = { - description: currentEditState.description !== undefined ? currentEditState.description : undefined, auditNote: currentEditState.auditNote !== undefined ? currentEditState.auditNote : undefined, + description: currentEditState.description !== undefined ? currentEditState.description : undefined, grossAmount: currentEditState.grossAmount !== undefined ? currentEditState.grossAmount : undefined, paymentStatus: currentEditState.paymentStatus !== undefined ? currentEditState.paymentStatus : undefined, releaseDate: currentEditState.releaseDate !== undefined ? currentEditState.releaseDate : undefined, @@ -225,8 +225,8 @@ const ListView: FC = (props: ListViewProps) => { } const updates: { - description?: string auditNote?: string + description?: string paymentStatus?: 'ON_HOLD_ADMIN' | 'OWED' | 'CANCELLED' releaseDate?: string paymentAmount?: number