Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/src/hooks/domain/usePermissions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ function usePermissions() {
&& isDefined(countryId)
&& !!userMe?.is_admin_for_countries?.includes(countryId)
);
const isRegionAdmin = (regionId: number | undefined) => (
const isRegionAdmin = (regionId: number | null | undefined) => (
!isGuestUser
&& isDefined(regionId)
&& !!userMe?.is_admin_for_regions?.includes(regionId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,9 @@ function ConfirmationModal(props: Props) {
const handleConfirmButtonChange = useCallback(() => {
if (isNewManageLocalUnit) {
addManageLocalUnit(manageLocalUnitsValues);
} else {
updateManageLocalUnit(manageLocalUnitsValues);
}
updateManageLocalUnit(manageLocalUnitsValues);
}, [isNewManageLocalUnit,
addManageLocalUnit, manageLocalUnitsValues, updateManageLocalUnit]);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,22 +67,13 @@ function ConfigureLocalUnitsModal(props: Props) {

const handleLocalUnitSwitchChange = useCallback((value: boolean, name: number) => {
setLocalUnitType(name);
if (isNotDefined(manageResponse)
&& isDefined(countryResponse)
) {
setManageLocalUnitsValues({
id: undefined,
country: countryResponse.id,
local_unit_type: name,
enabled: value,
});
}
if (isDefined(manageResponse)
&& isDefined(manageResponse[name])
&& isDefined(countryResponse)
) {

if (isDefined(countryResponse)) {
const isNew = isNotDefined(manageResponse) || isNotDefined(manageResponse[name]);
const manageId = isNew ? undefined : manageResponse[name]?.externallyManagedId;

setManageLocalUnitsValues({
id: manageResponse[name].externallyManagedId,
id: manageId,
country: countryResponse.id,
local_unit_type: name,
enabled: value,
Expand All @@ -97,8 +88,8 @@ function ConfigureLocalUnitsModal(props: Props) {
]);

const isNewManageLocalUnit = useMemo(() => {
if (isDefined(manageLocalUnitsValues)
&& isDefined(manageLocalUnitsValues.id)) {
if (isNotDefined(manageLocalUnitsValues)
|| isNotDefined(manageLocalUnitsValues?.id)) {
return true;
}
return false;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{
"namespace": "countryNsOverviewContextAndStructure",
"strings": {
"otherProfileOutputLabel": "Other Profiles",
"otherProfilePositionOutputLabel": "Position",
"otherProfileNumberOutputLabel": "Number"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
"localUnitViewDentist": "Dentist",
"localUnitViewNursingAid": "Nursing aid",
"localUnitViewMidwife": "Midwife",
"localUnitViewPharmacists": "Pharmacists",
"localUnitViewOtherProfiles": "Other profiles",
"localUnitViewRemovedOtherProfiles": "Removed Other profiles",
"localUnitViewOtherMedicalHeal": "Other medical heal",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -892,6 +892,18 @@ function LocalUnitView(props: Props) {
value={newValue?.health?.midwife}
/>
</DiffWrapper>
<DiffWrapper
hideOnPristine
value={newValue?.health?.pharmacists}
previousValue={oldValue?.health?.pharmacists}
diffViewEnabled
>
<TextOutput
strongValue
label={strings.localUnitViewPharmacists}
value={newValue?.health?.pharmacists}
/>
</DiffWrapper>
{isDefined(changedOtherProfiles) && changedOtherProfiles.length > 0 && (
<>
<span>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
"dentist": "Dentist",
"nursingAid": "Nursing aid",
"midwife": "Midwife",
"pharmacists": "Pharmacists",
"otherMedicalHeal": "Other medical heal",
"commentsNS": "Comments by the NS",
"addOtherProfilesButtonLabel": "Add Other Profiles",
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ const schema: LocalUnitsFormSchema = {
],
},
focal_point_position: {
required: true,
validations: [lengthSmallerThanCondition(50)],
},
focal_point_phone_number: {
Expand Down Expand Up @@ -250,6 +251,11 @@ const schema: LocalUnitsFormSchema = {
positiveIntegerCondition,
],
},
pharmacists: {
validations: [
positiveIntegerCondition,
],
},
other_medical_heal: {},
other_profiles: {
keySelector: (item) => item.client_id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,27 +64,30 @@ function LocalUnitsTableActions(props: Props) {
isLocalUnitRegionValidatorByType,
isSuperUser,
isGuestUser,
isCountryAdmin,
isRegionAdmin,
} = usePermissions();

const isLocked = status !== VALIDATED;

const countryAdmin = isCountryAdmin(countryDetails?.id);
const regionAdmin = isRegionAdmin(countryDetails?.region);

const isExternallyManaged = status === EXTERNALLY_MANAGED
|| (isDefined(localUnitType)
&& isDefined(manageResponse)
&& !!manageResponse[localUnitType]?.enabled);

const hasPermission = isAuthenticated
const hasValidatePermission = isAuthenticated
&& !isExternallyManaged
&& (isSuperUser
|| isLocalUnitGlobalValidatorByType(localUnitType)
|| isLocalUnitCountryValidatorByType(countryDetails?.id, localUnitType)
|| isLocalUnitRegionValidatorByType(countryDetails?.region, localUnitType));

const hasValidatePermission = isAuthenticated
&& (isSuperUser
|| isLocalUnitGlobalValidatorByType(localUnitType)
|| isLocalUnitCountryValidatorByType(countryDetails?.id, localUnitType)
|| isLocalUnitRegionValidatorByType(countryDetails?.region, localUnitType));
const hasAddEditLocalUnitPermission = !isLocked && (
(hasValidatePermission || countryAdmin || regionAdmin)
&& !isBulkUploadLocalUnit);

const [readOnlyLocalUnitModal, setReadOnlyLocalUnitModal] = useState(false);

Expand Down Expand Up @@ -165,7 +168,8 @@ function LocalUnitsTableActions(props: Props) {
>
{strings.localUnitActionsView}
</DropdownMenuItem>
{(hasPermission && !isBulkUploadLocalUnit) && (
{((hasValidatePermission || countryAdmin)
&& !isBulkUploadLocalUnit) && (
<DropdownMenuItem
type="button"
name={undefined}
Expand All @@ -174,7 +178,7 @@ function LocalUnitsTableActions(props: Props) {
{strings.localUnitActionsDelete}
</DropdownMenuItem>
)}
{!isLocked && (hasPermission && !isBulkUploadLocalUnit) && (
{hasAddEditLocalUnitPermission && (
<DropdownMenuItem
type="button"
name={localUnitId}
Expand All @@ -190,7 +194,7 @@ function LocalUnitsTableActions(props: Props) {
<LocalUnitValidateButton
onClick={handleValidateLocalUnitClick}
status={status}
hasValidatePermission={hasPermission}
hasValidatePermission={hasValidatePermission}
/>
)}
</TableActions>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ function LocalUnitsTable(props: Props) {
const {
isSuperUser,
isCountryAdmin,
isRegionAdmin,
isLocalUnitGlobalValidator,
isLocalUnitRegionValidator,
isLocalUnitCountryValidator,
Expand All @@ -71,6 +72,7 @@ function LocalUnitsTable(props: Props) {
|| isLocalUnitRegionValidator(countryResponse?.region ?? undefined);

const hasAddEditLocalUnitPermission = isCountryAdmin(countryResponse?.id)
|| isRegionAdmin(countryResponse?.region)
|| hasPermission;

const {
Expand Down
Loading