Skip to content

Commit b20e658

Browse files
shreeyash07frozenhelium
authored andcommitted
feat(status-update): update status in localunit table and form and modals
1 parent 38b4f01 commit b20e658

File tree

8 files changed

+66
-40
lines changed

8 files changed

+66
-40
lines changed

app/src/views/CountryNsOverviewContextAndStructure/NationalSocietyLocalUnits/LocalUnitImportModal/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ function LocalUnitBulkUploadModal(props: Props) {
181181
onClose={onClose}
182182
headerDescriptionContainerClassName={styles.headerDescriptionContent}
183183
childrenContainerClassName={styles.bulkUploadContent}
184-
headerDescription={importSummaryResponse?.status === BULK_UPLOAD_PENDING
184+
headerDescription={!pending
185185
? strings.modalDescription
186186
: strings.modalImportPendingDescription}
187187
contentViewType="vertical"

app/src/views/CountryNsOverviewContextAndStructure/NationalSocietyLocalUnits/LocalUnitStatus/index.tsx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@ import {
22
CheckboxCircleLineIcon,
33
CloseCircleLineIcon,
44
EditCircleLineIcon,
5+
LockLineIcon,
56
} from '@ifrc-go/icons';
67
import { Tooltip } from '@ifrc-go/ui';
78
import { _cs } from '@togglecorp/fujs';
89

910
import {
11+
EXTERNALLY_MANAGED,
1012
PENDING_VALIDATION,
1113
UNVALIDATED,
1214
VALIDATED,
@@ -37,6 +39,7 @@ function LocalUnitStatus(props: LocalUnitStatusProps) {
3739
value === VALIDATED && styles.validated,
3840
value === UNVALIDATED && styles.unvalidated,
3941
value === PENDING_VALIDATION && styles.pendingValidation,
42+
value === EXTERNALLY_MANAGED && styles.externallyManaged,
4043
className,
4144
)}
4245
>
@@ -55,6 +58,11 @@ function LocalUnitStatus(props: LocalUnitStatusProps) {
5558
className={styles.icon}
5659
/>
5760
)}
61+
{value === EXTERNALLY_MANAGED && (
62+
<LockLineIcon
63+
className={styles.icon}
64+
/>
65+
)}
5866
{!compact && valueDisplay}
5967
{compact && valueDisplay && (
6068
<Tooltip

app/src/views/CountryNsOverviewContextAndStructure/NationalSocietyLocalUnits/LocalUnitStatus/styles.module.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,8 @@
1717
&.pending-validation {
1818
color: var(--go-ui-color-blue);
1919
}
20+
21+
&.externally-managed {
22+
color: var(--go-ui-color-gray-60);
23+
}
2024
}

app/src/views/CountryNsOverviewContextAndStructure/NationalSocietyLocalUnits/LocalUnitsFormModal/LocalUnitsForm/index.tsx

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,9 @@ import {
6565
import { transformObjectError } from '#utils/restRequest/error';
6666

6767
import {
68+
EXTERNALLY_MANAGED,
6869
type ManageResponse,
70+
UNVALIDATED,
6971
VALIDATED,
7072
} from '../../common';
7173
import FormGrid from '../../FormGrid';
@@ -219,8 +221,20 @@ function LocalUnitsForm(props: Props) {
219221
pathVariables: isDefined(localUnitId) ? { id: localUnitId } : undefined,
220222
});
221223

224+
const isLocked = (
225+
isDefined(localUnitDetailsResponse?.status)
226+
&& !(localUnitDetailsResponse.status === VALIDATED)
227+
);
228+
229+
const isNewLocalUnit = localUnitDetailsResponse?.status === UNVALIDATED;
230+
231+
const isExternallyManaged = (localUnitDetailsResponse?.status === EXTERNALLY_MANAGED
232+
|| (isDefined(value.type)
233+
&& isDefined(manageResponse)
234+
&& !!manageResponse[value.type]?.enabled));
235+
222236
const readOnly = readOnlyFromProps
223-
|| localUnitDetailsResponse?.is_locked;
237+
|| isLocked || isExternallyManaged;
224238

225239
const {
226240
response: localUnitsOptions,
@@ -322,22 +336,16 @@ function LocalUnitsForm(props: Props) {
322336
},
323337
});
324338

325-
const isExternallyManaged = useMemo(() => {
326-
if (isDefined(value.type) && isDefined(manageResponse)) {
327-
return manageResponse[value.type]?.enabled;
328-
}
329-
return false;
330-
}, [value.type, manageResponse]);
331-
332339
const hasValidatePermission = isAuthenticated
333340
&& !isExternallyManaged
334341
&& (isSuperUser
335342
|| isLocalUnitGlobalValidatorByType(value.type)
336343
|| isLocalUnitCountryValidatorByType(countryResponse?.id, value.type)
337344
|| isLocalUnitRegionValidatorByType(countryResponse?.region, value.type));
338345

339-
const hasUpdatePermission = isCountryAdmin(countryResponse?.id)
340-
|| hasValidatePermission;
346+
const hasUpdatePermission = (isCountryAdmin(countryResponse?.id)
347+
|| hasValidatePermission)
348+
&& !isExternallyManaged;
341349

342350
const handleFormSubmit = useCallback(
343351
() => {
@@ -392,13 +400,14 @@ function LocalUnitsForm(props: Props) {
392400
localUnitPreviousResponse?.previous_data_details as unknown as LocalUnitResponse | undefined
393401
);
394402

395-
const showChanges = !localUnitDetailsResponse?.is_new_local_unit
396-
&& !!localUnitDetailsResponse?.is_locked
397-
&& isNotDefined(localUnitDetailsResponse.bulk_upload);
403+
const showChanges = !isNewLocalUnit
404+
&& isLocked
405+
&& !isExternallyManaged;
398406

399-
const showViewChanges = !localUnitDetailsResponse?.is_new_local_unit
407+
const showViewChanges = !isNewLocalUnit
400408
&& isDefined(localUnitId)
401-
&& !(localUnitDetailsResponse?.status === VALIDATED);
409+
&& isLocked
410+
&& !isExternallyManaged;
402411

403412
const permissionError = useMemo(() => {
404413
if (isExternallyManaged) {
@@ -467,7 +476,7 @@ function LocalUnitsForm(props: Props) {
467476
/>
468477
)}
469478
{readOnlyFromProps
470-
&& !localUnitDetailsResponse.is_locked
479+
&& !isLocked
471480
&& hasUpdatePermission && (
472481
<Button
473482
name={undefined}

app/src/views/CountryNsOverviewContextAndStructure/NationalSocietyLocalUnits/LocalUnitsTable/LocalUnitTableActions/index.tsx

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import {
22
useCallback,
3-
useMemo,
43
useState,
54
} from 'react';
65
import { TableActions } from '@ifrc-go/ui';
@@ -15,7 +14,11 @@ import useAuth from '#hooks/domain/useAuth';
1514
import useCountry from '#hooks/domain/useCountry';
1615
import usePermissions from '#hooks/domain/usePermissions';
1716

18-
import { type ManageResponse } from '../../common';
17+
import {
18+
EXTERNALLY_MANAGED,
19+
type ManageResponse,
20+
VALIDATED,
21+
} from '../../common';
1922
import LocalUnitDeleteModal from '../../LocalUnitDeleteModal';
2023
import LocalUnitsFormModal from '../../LocalUnitsFormModal';
2124
import LocalUnitValidateButton from '../../LocalUnitValidateButton';
@@ -33,7 +36,6 @@ export interface Props {
3336
onDeleteActionSuccess: () => void;
3437
onValidationActionSuccess: () => void;
3538
manageResponse: ManageResponse;
36-
isLocked: boolean;
3739
}
3840

3941
function LocalUnitsTableActions(props: Props) {
@@ -46,7 +48,6 @@ function LocalUnitsTableActions(props: Props) {
4648
isBulkUploadLocalUnit,
4749
onValidationActionSuccess,
4850
onDeleteActionSuccess,
49-
isLocked,
5051
manageResponse,
5152
} = props;
5253

@@ -64,12 +65,15 @@ function LocalUnitsTableActions(props: Props) {
6465
isGuestUser,
6566
} = usePermissions();
6667

67-
const isExternallyManaged = useMemo(() => {
68-
if (isDefined(localUnitType) && isDefined(manageResponse)) {
69-
return manageResponse[localUnitType]?.enabled;
70-
}
71-
return false;
72-
}, [localUnitType, manageResponse]);
68+
const isLocked = (
69+
isDefined(status)
70+
&& !(status === VALIDATED)
71+
);
72+
73+
const isExternallyManaged = (status === EXTERNALLY_MANAGED
74+
|| (isDefined(localUnitType)
75+
&& isDefined(manageResponse)
76+
&& !!manageResponse[localUnitType]?.enabled));
7377

7478
const hasPermission = isAuthenticated
7579
&& !isExternallyManaged

app/src/views/CountryNsOverviewContextAndStructure/NationalSocietyLocalUnits/LocalUnitsTable/i18n.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
"localUnitsTableAddress": "Address",
66
"localUnitsTableType": "Type",
77
"localUnitsTableFocal": "Focal Person",
8+
"localUnitsTableStatus": "Status",
89
"localUnitsTablePhoneNumber": "Phone Number",
910
"localUnitsTableEmail": "Email"
1011
}
11-
}
12+
}

app/src/views/CountryNsOverviewContextAndStructure/NationalSocietyLocalUnits/LocalUnitsTable/index.tsx

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -110,16 +110,6 @@ function LocalUnitsTable(props: Props) {
110110
const columns = useMemo(() => {
111111
if (hasAddEditLocalUnitPermission) {
112112
return [
113-
createElementColumn<LocalUnitsTableListItem, number, LocalUnitStatusProps>(
114-
'status',
115-
'',
116-
LocalUnitStatus,
117-
(_, item) => ({
118-
value: item.status,
119-
valueDisplay: item.status_details,
120-
compact: true,
121-
}),
122-
),
123113
createStringColumn<LocalUnitsTableListItem, number>(
124114
'branch_name',
125115
strings.localUnitsTableName,
@@ -157,6 +147,16 @@ function LocalUnitsTable(props: Props) {
157147
strings.localUnitsTableEmail,
158148
(item) => item.email,
159149
),
150+
createElementColumn<LocalUnitsTableListItem, number, LocalUnitStatusProps>(
151+
'status',
152+
strings.localUnitsTableStatus,
153+
LocalUnitStatus,
154+
(_, item) => ({
155+
value: item.status,
156+
valueDisplay: item.status_details,
157+
compact: true,
158+
}),
159+
),
160160
createElementColumn<LocalUnitsTableListItem, number, LocalUnitsTableActionsProps>(
161161
'actions',
162162
'',
@@ -165,7 +165,6 @@ function LocalUnitsTable(props: Props) {
165165
(_, item) => ({
166166
countryId: item.country,
167167
localUnitId: item.id,
168-
isLocked: item.is_locked,
169168
status: item.status,
170169
localUnitType: item.type,
171170
isBulkUploadLocalUnit: isDefined(item.bulk_upload),
@@ -206,7 +205,6 @@ function LocalUnitsTable(props: Props) {
206205
(_, item) => ({
207206
countryId: item.country,
208207
localUnitId: item.id,
209-
isLocked: item.is_locked,
210208
status: item.status,
211209
isBulkUploadLocalUnit: isDefined(item.bulk_upload),
212210
manageResponse,
@@ -230,6 +228,7 @@ function LocalUnitsTable(props: Props) {
230228
strings.localUnitsTableFocal,
231229
strings.localUnitsTablePhoneNumber,
232230
strings.localUnitsTableEmail,
231+
strings.localUnitsTableStatus,
233232
refetchLocalUnits,
234233
]);
235234

app/src/views/CountryNsOverviewContextAndStructure/NationalSocietyLocalUnits/common.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ export type ManageResponse = Record<number, {
1313
export const VALIDATED = 1 satisfies ValidationStatusKey;
1414
export const UNVALIDATED = 2 satisfies ValidationStatusKey;
1515
export const PENDING_VALIDATION = 3 satisfies ValidationStatusKey;
16+
export const EXTERNALLY_MANAGED = 4 satisfies ValidationStatusKey;
1617

1718
export const AUTHENTICATED = 'authenticated' satisfies RequestType;
1819
export const PUBLIC = 'public' satisfies RequestType;

0 commit comments

Comments
 (0)