Skip to content

Commit 2ab8f98

Browse files
authored
Merge pull request #1110 from topcoder-platform/PM-1304_allow-payment-description-update
PM-1304 - allow admin to update payment description
2 parents 827c1db + d09b7f8 commit 2ab8f98

File tree

2 files changed

+39
-2
lines changed

2 files changed

+39
-2
lines changed

src/apps/wallet-admin/src/home/tabs/payments/PaymentsTab.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ const ListView: FC<ListViewProps> = (props: ListViewProps) => {
7979
})
8080
const [editState, setEditState] = React.useState<{
8181
grossAmount?: number;
82+
description?: string;
8283
releaseDate?: Date;
8384
paymentStatus?: string;
8485
auditNote?: string;
@@ -93,6 +94,7 @@ const ListView: FC<ListViewProps> = (props: ListViewProps) => {
9394

9495
const handleValueUpdated = useCallback((updates: {
9596
auditNote?: string,
97+
description?: string,
9698
grossAmount?: number,
9799
paymentStatus?: string,
98100
releaseDate?: Date,
@@ -205,6 +207,7 @@ const ListView: FC<ListViewProps> = (props: ListViewProps) => {
205207
// Send to server only the fields that have changed
206208
const updateObj = {
207209
auditNote: currentEditState.auditNote !== undefined ? currentEditState.auditNote : undefined,
210+
description: currentEditState.description !== undefined ? currentEditState.description : undefined,
208211
grossAmount: currentEditState.grossAmount !== undefined ? currentEditState.grossAmount : undefined,
209212
paymentStatus: currentEditState.paymentStatus !== undefined ? currentEditState.paymentStatus : undefined,
210213
releaseDate: currentEditState.releaseDate !== undefined ? currentEditState.releaseDate : undefined,
@@ -223,6 +226,7 @@ const ListView: FC<ListViewProps> = (props: ListViewProps) => {
223226

224227
const updates: {
225228
auditNote?: string
229+
description?: string
226230
paymentStatus?: 'ON_HOLD_ADMIN' | 'OWED' | 'CANCELLED'
227231
releaseDate?: string
228232
paymentAmount?: number
@@ -232,6 +236,7 @@ const ListView: FC<ListViewProps> = (props: ListViewProps) => {
232236
winningsId: paymentId,
233237
}
234238

239+
if (updateObj.description) updates.description = updateObj.description
235240
if (paymentStatus) updates.paymentStatus = paymentStatus
236241
if (paymentStatus !== 'CANCELLED') {
237242
if (updateObj.releaseDate !== undefined) updates.releaseDate = updateObj.releaseDate.toISOString()

src/apps/wallet-admin/src/lib/components/payment-edit/PaymentEdit.tsx

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,15 @@ interface PaymentEditFormProps {
1818
releaseDate, grossAmount, paymentStatus, auditNote,
1919
}: {
2020
releaseDate?: Date
21+
description?: string
2122
grossAmount?: number
2223
paymentStatus?: string
2324
auditNote?: string
2425
}) => void
2526
}
2627

2728
const PaymentEdit: React.FC<PaymentEditFormProps> = (props: PaymentEditFormProps) => {
29+
const [description, setDescription] = useState('')
2830
const [paymentStatus, setPaymentStatus] = useState('')
2931
const [releaseDate, setReleaseDate] = useState(new Date())
3032
const [grossAmount, setGrossAmount] = useState(0)
@@ -35,6 +37,7 @@ const PaymentEdit: React.FC<PaymentEditFormProps> = (props: PaymentEditFormProps
3537

3638
const initialValues = useMemo(() => ({
3739
auditNote: '',
40+
description: props.payment.description,
3841
grossAmount: props.payment.grossAmountNumber,
3942
paymentStatus: props.payment.status,
4043
releaseDate: props.payment.releaseDateObj,
@@ -85,6 +88,15 @@ const PaymentEdit: React.FC<PaymentEditFormProps> = (props: PaymentEditFormProps
8588
})
8689
}
8790

91+
break
92+
case 'description':
93+
setDescription(value as string)
94+
if (props.onValueUpdated) {
95+
props.onValueUpdated({
96+
description: value as string,
97+
})
98+
}
99+
88100
break
89101
case 'releaseDate':
90102
setReleaseDate(value as Date)
@@ -110,13 +122,17 @@ const PaymentEdit: React.FC<PaymentEditFormProps> = (props: PaymentEditFormProps
110122
}
111123

112124
useEffect(() => {
125+
setDescription(props.payment.description)
113126
setPaymentStatus(props.payment.status)
114127
setReleaseDate(props.payment.releaseDateObj)
115128
setGrossAmount(props.payment.grossAmountNumber)
116129
}, [props.payment])
117130

118131
useEffect(() => {
119132
const valuesToCheck = [{
133+
key: 'description',
134+
value: description,
135+
}, {
120136
key: 'grossPayment',
121137
value: grossAmount,
122138
}, {
@@ -132,14 +148,17 @@ const PaymentEdit: React.FC<PaymentEditFormProps> = (props: PaymentEditFormProps
132148

133149
const isDirty = valuesToCheck.some(x => x.value !== initialValues[x.key as keyof typeof initialValues])
134150
setDirty(isDirty)
135-
}, [grossAmount, paymentStatus, releaseDate, auditNote, initialValues])
151+
}, [description, grossAmount, paymentStatus, releaseDate, auditNote, initialValues])
136152

137153
useEffect(() => {
138154
if (props.canSave) {
139155
if (!dirty) {
140156
props.canSave(false)
141157
} else {
142158
const valuesToCheck = [{
159+
key: 'description',
160+
value: description,
161+
}, {
143162
key: 'grossPayment',
144163
value: grossAmount,
145164
}, {
@@ -154,7 +173,7 @@ const PaymentEdit: React.FC<PaymentEditFormProps> = (props: PaymentEditFormProps
154173
props.canSave(haveChange && grossAmountErrorString.length === 0 && auditNote.length > 0)
155174
}
156175
}
157-
}, [dirty, auditNote, props, grossAmountErrorString.length, grossAmount, paymentStatus, releaseDate, initialValues])
176+
}, [dirty, auditNote, props, grossAmountErrorString.length, description, grossAmount, paymentStatus, releaseDate, initialValues])
158177

159178
const getLink = (externalId: string): string => `${TOPCODER_URL}/challenges/${externalId}`
160179

@@ -208,8 +227,21 @@ const PaymentEdit: React.FC<PaymentEditFormProps> = (props: PaymentEditFormProps
208227
error={grossAmountErrorString}
209228
value={props.payment.grossAmountNumber.toString()}
210229
onChange={e => handleInputChange('grossPayment', parseFloat(e.target.value))}
230+
/>
211231

232+
<InputText
233+
name='description'
234+
label='Description'
235+
type='text'
236+
disabled={disableEdits}
237+
placeholder='Modify Description'
238+
dirty
239+
tabIndex={0}
240+
error={!description?.length ? 'Description can\'t be empty' : ''}
241+
value={props.payment.description.toString()}
242+
onChange={e => handleInputChange('description', e.target.value)}
212243
/>
244+
213245
<InputSelect
214246
tabIndex={-1}
215247
dirty

0 commit comments

Comments
 (0)