|
| 1 | +import { |
| 2 | + useCallback, |
| 3 | + useState, |
| 4 | +} from 'react'; |
1 | 5 | import { |
2 | 6 | DocumentPdfLineIcon, |
3 | 7 | DownloadTwoLineIcon, |
4 | 8 | } from '@ifrc-go/icons'; |
5 | 9 | import { |
6 | 10 | Button, |
7 | | - TableActions, |
| 11 | + ListView, |
8 | 12 | } from '@ifrc-go/ui'; |
9 | | -import { |
10 | | - useBooleanState, |
11 | | - useTranslation, |
12 | | -} from '@ifrc-go/ui/hooks'; |
| 13 | +import { useTranslation } from '@ifrc-go/ui/hooks'; |
13 | 14 | import { |
14 | 15 | isDefined, |
15 | 16 | isNotDefined, |
@@ -41,102 +42,129 @@ function EapTableActions(props: Props) { |
41 | 42 | details, |
42 | 43 | } = expandedListItem; |
43 | 44 |
|
| 45 | + const [exportWithDiffView, setExportWithDiffView] = useState(false); |
| 46 | + const [showExportModal, setShowExportModal] = useState(false); |
| 47 | + |
44 | 48 | 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 | + }, []); |
52 | 59 |
|
53 | 60 | 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 && ( |
75 | 64 | <Link |
76 | | - to="simplifiedEapForm" |
| 65 | + to="simplifiedEapExport" |
77 | 66 | 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} />} |
80 | 72 | > |
81 | | - {strings.eapStartSimplifiedLink} |
| 73 | + Preview export |
82 | 74 | </Link> |
| 75 | + )} |
| 76 | + {type === 'development' && details?.data.is_locked && isDefined(eap.review_checklist_file) && ( |
83 | 77 | <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 />} |
88 | 81 | > |
89 | | - {strings.eapStartFullLink} |
| 82 | + Review Checklist |
90 | 83 | </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 && ( |
100 | 148 | <Link |
101 | | - to="simplifiedEapForm" |
| 149 | + to="fullEapForm" |
102 | 150 | urlParams={{ eapId: eap.id }} |
103 | 151 | styleVariant="outline" |
104 | 152 | colorVariant="primary" |
105 | 153 | > |
106 | | - {strings.eapEditSimplifiedLink} |
| 154 | + {strings.eapEditFullLink} |
107 | 155 | </Link> |
108 | 156 | )} |
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> |
131 | 158 | {showExportModal && isDefined(eap.eap_type) && ( |
132 | 159 | <EapExportModal |
133 | 160 | eapId={eap.id} |
134 | 161 | eapType={eap.eap_type} |
135 | 162 | onClose={setShowExportModalFalse} |
136 | 163 | version={details?.data.version} |
| 164 | + diff={exportWithDiffView} |
137 | 165 | /> |
138 | 166 | )} |
139 | | - </TableActions> |
| 167 | + </> |
140 | 168 | ); |
141 | 169 | } |
142 | 170 |
|
|
0 commit comments