Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(feat): Add user role scope #554

Merged
merged 4 commits into from
Jan 21, 2025
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
fix delay provider data load
Ogollah committed Jan 17, 2025
commit ecb44af316501337da505790b2611448c8ffda65
Original file line number Diff line number Diff line change
@@ -81,6 +81,10 @@ const ManageUserWorkspace: React.FC<ManageUserWorkspaceProps> = ({
const { stockLocations } = useStockTagLocations();

const { providerAttributeType = [] } = useProviderAttributeType();

const { roles = [], isLoading } = useRoles();
const { rolesConfig, error } = useSystemUserRoleConfigSetting();
const { attributeTypes = [] } = usePersonAttribute();
// Memoize provider attribute mappings
const attributeTypeMapping = useMemo(() => {
return {
@@ -114,24 +118,27 @@ const ManageUserWorkspace: React.FC<ManageUserWorkspaceProps> = ({

const isInitialValuesEmpty = Object.keys(initialUserValue).length === 0;
type UserFormSchema = z.infer<typeof userManagementFormSchema>;
const formDefaultValues = !isInitialValuesEmpty
? {
...initialUserValue,
...extractNameParts(initialUserValue.person?.display || ''),
phoneNumber: extractAttributeValue(initialUserValue.person?.attributes, 'Telephone'),
email: extractAttributeValue(initialUserValue.person?.attributes, 'Email'),
roles:
initialUserValue.roles?.map((role) => ({
uuid: role.uuid,
display: role.display,
description: role.description,
})) || [],
gender: initialUserValue.person?.gender || 'M',
providerLicense: providerLicenseNumber,
licenseExpiryDate: licenseExpiryDate,
primaryFacility: primaryFacility,
}
: {};
const formDefaultValues = useMemo(() => {
if (isInitialValuesEmpty) {
return {};
}
return {
...initialUserValue,
...extractNameParts(initialUserValue.person?.display || ''),
phoneNumber: extractAttributeValue(initialUserValue.person?.attributes, 'Telephone'),
email: extractAttributeValue(initialUserValue.person?.attributes, 'Email'),
roles:
initialUserValue.roles?.map((role) => ({
uuid: role.uuid,
display: role.display,
description: role.description,
})) || [],
gender: initialUserValue.person?.gender || 'M',
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is the gender or here explicitly M ? should it be empty?

providerLicense: providerLicenseNumber,
licenseExpiryDate: licenseExpiryDate,
primaryFacility: primaryFacility,
};
}, [isInitialValuesEmpty, initialUserValue, providerLicenseNumber, licenseExpiryDate, primaryFacility]);

function extractNameParts(display = '') {
const nameParts = display.split(' ');
@@ -152,11 +159,15 @@ const ManageUserWorkspace: React.FC<ManageUserWorkspaceProps> = ({
defaultValues: formDefaultValues,
});

const { reset } = userFormMethods;

const { errors, isSubmitting, isDirty } = userFormMethods.formState;

const { roles = [], isLoading } = useRoles();
const { rolesConfig, error } = useSystemUserRoleConfigSetting();
const { attributeTypes = [] } = usePersonAttribute();
useEffect(() => {
if (!loadingProvider && !loadingLocation) {
reset(formDefaultValues);
}
}, [loadingProvider, loadingLocation, formDefaultValues, reset]);

useEffect(() => {
if (isDirty) {
@@ -168,6 +179,7 @@ const ManageUserWorkspace: React.FC<ManageUserWorkspaceProps> = ({
const emailAttribute = attributeTypes.find((attr) => attr.name === 'Email address')?.uuid || '';
const telephoneAttribute = attributeTypes.find((attr) => attr.name === 'Telephone contact')?.uuid || '';
const setProvider = data.providerIdentifiers;
const editProvider = data.isEditProvider;
const providerUUID = provider[0]?.uuid || '';
const roleName = data.roles?.[0]?.display || '';

@@ -265,7 +277,7 @@ const ManageUserWorkspace: React.FC<ManageUserWorkspaceProps> = ({
);
}
}
if (setProvider) {
if (setProvider || editProvider) {
try {
const providerUrl = providerUUID ? `${restBaseUrl}/provider/${providerUUID}` : `${restBaseUrl}/provider`;
const personUUID = response.person.uuid;
@@ -573,6 +585,26 @@ const ManageUserWorkspace: React.FC<ManageUserWorkspaceProps> = ({
)}
/>
</ResponsiveWrapper>
<ResponsiveWrapper>
<Controller
name="isEditProvider"
control={userFormMethods.control}
render={({ field }) => (
<CheckboxGroup
legendText={t('editProvider', 'Edit Provider Details')}
className={styles.multilineCheckboxLabel}>
<Checkbox
className={styles.checkboxLabelSingleLine}
{...field}
id="isEditProvider"
labelText={t('EditProviderDetails', 'Edit provider details?')}
checked={field.value || false}
onChange={(e) => field.onChange(e.target.checked)}
/>
</CheckboxGroup>
)}
/>
</ResponsiveWrapper>
</>
) : (
<>
Original file line number Diff line number Diff line change
@@ -55,6 +55,7 @@ const UserManagementFormSchema = () => {

activeTo: z.string().optional(),
activeFrom: z.string().optional(),
isEditProvider: z.boolean().optional(),
});

return { userManagementFormSchema };

Unchanged files with check annotations Beta

version: module[1].version,
name: module[0].substring(module[0].indexOf('/') + 1),
}));
}, [window.installedModules]);

Check warning on line 12 in packages/esm-version-app/src/hooks/useFrontendModules.tsx

GitHub Actions / build

React Hook useMemo has an unnecessary dependency: 'window.installedModules'. Either exclude it or remove the dependency array. Outer scope values like 'window.installedModules' aren't valid dependencies because mutating them doesn't re-render the component
}
status: status,
handleProcessReferral,
});
}, [referralData]);

Check warning on line 23 in packages/esm-shr-app/src/referrals/referrals-actions.component.tsx

GitHub Actions / build

React Hook useCallback has missing dependencies: 'handleProcessReferral' and 'status'. Either include them or remove the dependency array
const handleProcessReferral = useCallback(() => {
processCommunityReferral(referralData.messageId)
.then((res) => {
isLowContrast: true,
});
});
}, []);

Check warning on line 47 in packages/esm-shr-app/src/referrals/referrals-actions.component.tsx

GitHub Actions / build

React Hook useCallback has missing dependencies: 'referralData.messageId' and 't'. Either include them or remove the dependency array
return (
<>
onActionButtonClick: () => {},
});
}
}, [expiryDate]);

Check warning on line 27 in packages/esm-providers-app/src/provider-alert-message/alert-message-banner.component.tsx

GitHub Actions / build

React Hook useEffect has a missing dependency: 'messageText'. Either include it or remove the dependency array
return null;
};
const [switchItem, setSwitcherItem] = useState<SwitcherItem>({ index: 0 });
const patientEnrollments = useMemo(
() => (isLoading ? [] : enrollments[switchItem?.name || first(switcherHeaders)]),
[enrollments, isLoading, switchItem?.name, switcherHeaders, isValidating],

Check warning on line 33 in packages/esm-care-panel-app/src/care-panel/care-panel.component.tsx

GitHub Actions / build

React Hook useMemo has an unnecessary dependency: 'isValidating'. Either exclude it or remove the dependency array
);
if (isLoading) {
})
: launchStartVisitPrompt();
},
[currentVisit],

Check warning on line 80 in packages/esm-care-panel-app/src/care-programs/care-programs.component.tsx

GitHub Actions / build

React Hook useCallback has a missing dependency: 'handleMutations'. Either include it or remove the dependency array
);
const rows = useMemo(
),
};
}),
[carePrograms, isValidating],

Check warning on line 113 in packages/esm-care-panel-app/src/care-programs/care-programs.component.tsx

GitHub Actions / build

React Hook useMemo has a missing dependency: 'handleCareProgramClick'. Either include it or remove the dependency array
);
const headers = [
} finally {
setIsLoading(false);
}
}, [bill, lineItem, onClose, t]);

Check warning on line 74 in packages/esm-billing-app/src/billable-services/bill-manager/modals/refund-bill.modal.tsx

GitHub Actions / build

React Hook useCallback has missing dependencies: 'billableServiceUuid' and 'itemUuid'. Either include them or remove the dependency array
return (
<>
useEffect(() => {
promptBeforeClosing(() => isDirty);
}, [isDirty]);

Check warning on line 63 in packages/esm-billing-app/src/billable-services/bill-manager/workspaces/edit-bill/edit-bill-form.workspace.tsx

GitHub Actions / build

React Hook useEffect has a missing dependency: 'promptBeforeClosing'. Either include it or remove the dependency array. If 'promptBeforeClosing' changes too often, find the parent component that defines it and wrap that definition in useCallback
const onSubmit: SubmitHandler<EditBillFormData> = async (formData) => {
const updateBill = createEditBillPayload(lineItem, formData, bill, formData.adjustmentReason);