Skip to content

Commit 4c88096

Browse files
committed
feat(eap): add option to export with changes
1 parent 56e1dca commit 4c88096

File tree

4 files changed

+120
-79
lines changed

4 files changed

+120
-79
lines changed

app/src/views/AccountMyFormsEap/EapStatus/index.tsx

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import {
2020
import DropdownMenuItem from '#components/DropdownMenuItem';
2121
import { type components } from '#generated/types';
2222
import useGlobalEnums from '#hooks/domain/useGlobalEnums';
23+
import useAlert from '#hooks/useAlert';
2324
import {
2425
EAP_STATUS_ACTIVATED,
2526
EAP_STATUS_APPROVED,
@@ -68,6 +69,8 @@ function EapStatus(props: Props) {
6869
onStatusUpdate,
6970
} = props;
7071

72+
const alert = useAlert();
73+
7174
const { eap_eap_status: eapStatusOptions } = useGlobalEnums();
7275
const [newStatus, setNewStatus] = useState<EapStatus | undefined>();
7376
const [checklistFile, setChecklistFile] = useState<File | undefined>();
@@ -90,9 +93,19 @@ function EapStatus(props: Props) {
9093
if (onStatusUpdate) {
9194
onStatusUpdate();
9295
}
93-
// TODO alert on status update
96+
97+
alert.show(
98+
'Status updated successfully!',
99+
{ variant: 'success' },
100+
);
94101
},
95102
formData: true,
103+
onFailure: () => {
104+
alert.show(
105+
'Failed to update the status!',
106+
{ variant: 'danger' },
107+
);
108+
},
96109
});
97110

98111
// FIXME: fix typings in the server

app/src/views/AccountMyFormsEap/EapTableActions/index.tsx

Lines changed: 104 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
1+
import {
2+
useCallback,
3+
useState,
4+
} from 'react';
15
import {
26
DocumentPdfLineIcon,
37
DownloadTwoLineIcon,
48
} from '@ifrc-go/icons';
59
import {
610
Button,
7-
TableActions,
11+
ListView,
812
} from '@ifrc-go/ui';
9-
import {
10-
useBooleanState,
11-
useTranslation,
12-
} from '@ifrc-go/ui/hooks';
13+
import { useTranslation } from '@ifrc-go/ui/hooks';
1314
import {
1415
isDefined,
1516
isNotDefined,
@@ -41,102 +42,129 @@ function EapTableActions(props: Props) {
4142
details,
4243
} = expandedListItem;
4344

45+
const [exportWithDiffView, setExportWithDiffView] = useState(false);
46+
const [showExportModal, setShowExportModal] = useState(false);
47+
4448
const strings = useTranslation(i18n);
45-
const [
46-
showExportModal,
47-
{
48-
setTrue: setShowExportModalTrue,
49-
setFalse: setShowExportModalFalse,
50-
},
51-
] = useBooleanState(false);
49+
50+
const setShowExportModalTrue = useCallback((withDiff?: boolean) => {
51+
setExportWithDiffView(!!withDiff);
52+
setShowExportModal(true);
53+
}, []);
54+
55+
const setShowExportModalFalse = useCallback(() => {
56+
setExportWithDiffView(false);
57+
setShowExportModal(false);
58+
}, []);
5259

5360
return (
54-
<TableActions>
55-
{type === 'development' && details?.data.is_locked && isDefined(eap.review_checklist_file) && (
56-
<Link
57-
external
58-
href={eap.review_checklist_file}
59-
before={<DownloadTwoLineIcon />}
60-
>
61-
Review Checklist
62-
</Link>
63-
)}
64-
{type === 'development' && eap.eap_type === EAP_TYPE_SIMPLIFIED && (
65-
<Button
66-
name={undefined}
67-
onClick={setShowExportModalTrue}
68-
// FIXME: use strings
69-
>
70-
Export
71-
</Button>
72-
)}
73-
{type === 'development' && isNotDefined(eap.eap_type) && isNotDefined(details) && (
74-
<>
61+
<>
62+
<ListView layout="block">
63+
{type === 'development' && eap.eap_type === EAP_TYPE_SIMPLIFIED && (
7564
<Link
76-
to="simplifiedEapForm"
65+
to="simplifiedEapExport"
7766
urlParams={{ eapId: eap.id }}
78-
styleVariant="outline"
79-
colorVariant="primary"
67+
urlSearch={isDefined(details?.data.version)
68+
? `version=${details.data.version}`
69+
: undefined}
70+
title="Preview export"
71+
before={<DocumentPdfLineIcon fontSize={18} />}
8072
>
81-
{strings.eapStartSimplifiedLink}
73+
Preview export
8274
</Link>
75+
)}
76+
{type === 'development' && details?.data.is_locked && isDefined(eap.review_checklist_file) && (
8377
<Link
84-
to="fullEapForm"
85-
urlParams={{ eapId: eap.id }}
86-
styleVariant="outline"
87-
colorVariant="primary"
78+
external
79+
href={eap.review_checklist_file}
80+
before={<DownloadTwoLineIcon />}
8881
>
89-
{strings.eapStartFullLink}
82+
Review Checklist
9083
</Link>
91-
</>
92-
)}
93-
{type === 'development'
94-
&& !details?.data.is_locked
95-
&& eap.eap_type === EAP_TYPE_SIMPLIFIED
96-
&& (eap.status === EAP_STATUS_UNDER_DEVELOPMENT
97-
|| (eap.status === EAP_STATUS_NS_ADDRESSING_COMMENTS
98-
&& eap.latest_simplified_eap === details?.data.id))
99-
&& (
84+
)}
85+
{type === 'development' && eap.eap_type === EAP_TYPE_SIMPLIFIED && (
86+
<Button
87+
name={false}
88+
onClick={setShowExportModalTrue}
89+
before={<DownloadTwoLineIcon />}
90+
styleVariant="action"
91+
// FIXME: use strings
92+
>
93+
Export
94+
</Button>
95+
)}
96+
{type === 'development'
97+
&& eap.eap_type === EAP_TYPE_SIMPLIFIED
98+
&& isDefined(details?.data.version)
99+
&& details.data.version > 1
100+
&& (
101+
<Button
102+
name
103+
onClick={setShowExportModalTrue}
104+
before={<DownloadTwoLineIcon />}
105+
styleVariant="action"
106+
// FIXME: use strings
107+
>
108+
Export with changes
109+
</Button>
110+
)}
111+
{type === 'registration' && isNotDefined(eap.eap_type) && isNotDefined(details) && (
112+
<ListView>
113+
<Link
114+
to="simplifiedEapForm"
115+
urlParams={{ eapId: eap.id }}
116+
styleVariant="outline"
117+
colorVariant="primary"
118+
>
119+
{strings.eapStartSimplifiedLink}
120+
</Link>
121+
<Link
122+
to="fullEapForm"
123+
urlParams={{ eapId: eap.id }}
124+
styleVariant="outline"
125+
colorVariant="primary"
126+
>
127+
{strings.eapStartFullLink}
128+
</Link>
129+
</ListView>
130+
)}
131+
{type === 'development'
132+
&& !details?.data.is_locked
133+
&& eap.eap_type === EAP_TYPE_SIMPLIFIED
134+
&& (eap.status === EAP_STATUS_UNDER_DEVELOPMENT
135+
|| (eap.status === EAP_STATUS_NS_ADDRESSING_COMMENTS
136+
&& eap.latest_simplified_eap === details?.data.id))
137+
&& (
138+
<Link
139+
to="simplifiedEapForm"
140+
urlParams={{ eapId: eap.id }}
141+
styleVariant="outline"
142+
colorVariant="primary"
143+
>
144+
{strings.eapEditSimplifiedLink}
145+
</Link>
146+
)}
147+
{type === 'development' && !details?.data.is_locked && eap.eap_type === EAP_TYPE_FULL && (
100148
<Link
101-
to="simplifiedEapForm"
149+
to="fullEapForm"
102150
urlParams={{ eapId: eap.id }}
103151
styleVariant="outline"
104152
colorVariant="primary"
105153
>
106-
{strings.eapEditSimplifiedLink}
154+
{strings.eapEditFullLink}
107155
</Link>
108156
)}
109-
{type === 'development' && !details?.data.is_locked && eap.eap_type === EAP_TYPE_FULL && (
110-
<Link
111-
to="fullEapForm"
112-
urlParams={{ eapId: eap.id }}
113-
styleVariant="outline"
114-
colorVariant="primary"
115-
>
116-
{strings.eapEditFullLink}
117-
</Link>
118-
)}
119-
{type === 'development' && eap.eap_type === EAP_TYPE_SIMPLIFIED && (
120-
<Link
121-
to="simplifiedEapExport"
122-
urlParams={{ eapId: eap.id }}
123-
urlSearch={isDefined(details?.data.version)
124-
? `version=${details.data.version}`
125-
: undefined}
126-
title="Preview export"
127-
>
128-
<DocumentPdfLineIcon fontSize={18} />
129-
</Link>
130-
)}
157+
</ListView>
131158
{showExportModal && isDefined(eap.eap_type) && (
132159
<EapExportModal
133160
eapId={eap.id}
134161
eapType={eap.eap_type}
135162
onClose={setShowExportModalFalse}
136163
version={details?.data.version}
164+
diff={exportWithDiffView}
137165
/>
138166
)}
139-
</TableActions>
167+
</>
140168
);
141169
}
142170

app/src/views/AccountMyFormsEap/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ export function Component() {
214214
eap: eapListItem,
215215
type: 'development',
216216
details: undefined,
217-
disabled: false,
217+
disabled: true,
218218
} satisfies EapExpandedListItem)
219219
: undefined
220220
),

0 commit comments

Comments
 (0)