Skip to content

Commit f636b65

Browse files
committed
fix: code review
1 parent d6e8f88 commit f636b65

4 files changed

Lines changed: 57 additions & 12 deletions

File tree

src/components/v5/common/CompletedAction/partials/PaymentBuilder/partials/CancelModal/CancelModal.tsx

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
WarningCircle,
77
} from '@phosphor-icons/react';
88
import React, { useState, type FC } from 'react';
9+
import { defineMessages } from 'react-intl';
910
import { toast } from 'react-toastify';
1011

1112
import { getRole } from '~constants/permissions.ts';
@@ -50,6 +51,22 @@ import RadioButtons from './partials/RadioButtons.tsx';
5051
import { PenaliseOptions } from './partials/types.ts';
5152
import { type CancelModalProps } from './types.ts';
5253

54+
const displayName =
55+
'v5.common.CompletedAction.partials.PaymentBuilder.partials.CancelModal';
56+
57+
const MSG = defineMessages({
58+
noPenaliseInfo: {
59+
id: `${displayName}.noPenaliseInfot`,
60+
defaultMessage:
61+
'The payment creator will keep their full stake and reputation.',
62+
},
63+
penaliseInfo: {
64+
id: `${displayName}.penaliseInfo`,
65+
defaultMessage:
66+
'The payment creator will lose their full stake and the relative amount of reputation. Penalised funds are burned.',
67+
},
68+
});
69+
5370
const CancelModal: FC<CancelModalProps> = ({
5471
isOpen,
5572
onClose,
@@ -114,7 +131,7 @@ const CancelModal: FC<CancelModalProps> = ({
114131
});
115132
const associatedActionId = getMotionAssociatedActionId(actionData);
116133

117-
const handleFundExpenditure = async ({ decisionMethod, penalise }) => {
134+
const handleCancelExpenditure = async ({ decisionMethod, penalise }) => {
118135
setIsSubmitting(true);
119136
try {
120137
if (!expenditure) {
@@ -211,7 +228,7 @@ const CancelModal: FC<CancelModalProps> = ({
211228
{isExpenditureLocked ? (
212229
<Form
213230
className="flex flex-grow flex-col"
214-
onSubmit={handleFundExpenditure}
231+
onSubmit={handleCancelExpenditure}
215232
validationSchema={
216233
isActionStaked ? stakedValidationSchema : validationSchema
217234
}
@@ -252,8 +269,7 @@ const CancelModal: FC<CancelModalProps> = ({
252269
className="shrink-0 text-success-400"
253270
/>
254271
<p className="text-md">
255-
The payment creator will keep their full stake and
256-
reputation
272+
{formatText(MSG.noPenaliseInfo)}
257273
</p>
258274
</div>
259275
)}
@@ -264,9 +280,7 @@ const CancelModal: FC<CancelModalProps> = ({
264280
className="shrink-0 text-negative-400"
265281
/>
266282
<p className="text-md">
267-
The payment creator will lose their full stake and
268-
the relative amount of reputation. Penalised funds
269-
are burned.
283+
{formatText(MSG.penaliseInfo)}
270284
</p>
271285
</div>
272286
)}

src/components/v5/common/CompletedAction/partials/PaymentBuilder/partials/CancelModal/partials/RadioButtons.tsx

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,30 @@
11
import React from 'react';
22
import { useController } from 'react-hook-form';
3+
import { defineMessages } from 'react-intl';
4+
5+
import { formatText } from '~utils/intl.ts';
36

47
import RadioButton from './RadioButton.tsx';
58
import { PenaliseOptions } from './types.ts';
69

10+
const displayName =
11+
'v5.common.CompletedAction.partials.PaymentBuilder.partials.CancelModal';
12+
13+
const MSG = defineMessages({
14+
noPenaliseRadio: {
15+
id: `${displayName}.noPenaliseRadio`,
16+
defaultMessage: `No, don't penalise`,
17+
},
18+
penaliseRadio: {
19+
id: `${displayName}.penaliseRadio`,
20+
defaultMessage: 'Yes, penalise',
21+
},
22+
requiredOptionInfo: {
23+
id: `${displayName}.requiredOptionInfo`,
24+
defaultMessage: 'A penalised option is required',
25+
},
26+
});
27+
728
const RadioButtons = () => {
829
const {
930
field: { onChange },
@@ -23,7 +44,7 @@ const RadioButtons = () => {
2344
onChange={onChange}
2445
hasError={!!error}
2546
>
26-
Yes, penalise
47+
{formatText(MSG.penaliseRadio)}
2748
</RadioButton>
2849
</li>
2950
<li className="w-full sm:w-1/2">
@@ -34,13 +55,13 @@ const RadioButtons = () => {
3455
onChange={onChange}
3556
hasError={!!error}
3657
>
37-
No, don&apos;t penalise
58+
{formatText(MSG.noPenaliseRadio)}
3859
</RadioButton>
3960
</li>
4061
</ul>
4162
{!!error && (
4263
<p className="mt-1 text-sm text-negative-400">
43-
A penalised option is required
64+
{formatText(MSG.requiredOptionInfo)}
4465
</p>
4566
)}
4667
</div>

src/components/v5/common/CompletedAction/partials/PaymentBuilder/partials/PaymentBuilderWidget/PaymentBuilderWidget.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -685,9 +685,12 @@ const PaymentBuilderWidget: FC<PaymentBuilderWidgetProps> = ({ action }) => {
685685
);
686686

687687
items.splice(
688-
fundingItemIndex + 1,
688+
isExpenditureFunded ? fundingItemIndex + 1 : fundingItemIndex,
689689
0,
690-
getCancelItem(2, segregatedCancelActions.funding),
690+
getCancelItem(
691+
isExpenditureFunded ? 2 : 1,
692+
segregatedCancelActions.funding,
693+
),
691694
);
692695
}
693696
}

src/components/v5/common/CompletedAction/partials/PaymentBuilder/partials/PaymentBuilderWidget/utils.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,13 @@ export const getCancelStepIndex = (
253253
return fundingItemIndex;
254254
}
255255

256+
if (
257+
isExpenditureFullFunded &&
258+
expenditure.cancellingActions?.items?.[0]?.type === 'CANCEL_EXPENDITURE'
259+
) {
260+
return fundingItemIndex + expenditure.cancellingActions.items.length + 1;
261+
}
262+
256263
if (isExpenditureFullFunded && !isExpenditureFinalized) {
257264
return fundingItemIndex + 2;
258265
}

0 commit comments

Comments
 (0)