Skip to content

Commit

Permalink
fix undifined value
Browse files Browse the repository at this point in the history
  • Loading branch information
Ogollah committed Jan 22, 2025
1 parent dd9e30c commit cc7612b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -211,35 +211,31 @@ const ManageUserWorkspace: React.FC<ManageUserWorkspaceProps> = ({
const providerUUID = provider[0]?.uuid || '';
const roleName = data.roles?.[0]?.display || '';

const hasValidLocations = Array.isArray(data.operationLocation) && data.operationLocation.length > 0;
const hasValidLocations = data.operationLocation?.length > 0;
const hasEnabledFlag = data.enabled !== undefined && data.enabled !== null;
const hasOperationTypes = Array.isArray(data.stockOperation) && data.stockOperation.length > 0;
const hasDateRange = data.dateRange.activeFrom && data.dateRange.activeTo;
const hasOperationTypes = data.stockOperation?.length > 0;
const hasDateRange = data.dateRange?.activeFrom && data.dateRange?.activeTo;
const hasValidRoleConditions =
hasValidLocations && hasEnabledFlag && hasOperationTypes && (data.permanent || hasDateRange);

const userRoleScopePayload: Partial<UserRoleScope> = {
...(hasValidRoleConditions && { role: roleName }),
locations: hasValidLocations
? data.operationLocation.map((loc) => ({
locationUuid: loc.locationUuid,
locationName: loc.locationName,
enableDescendants: false,
}))
: [],
locations: data.operationLocation?.map((loc) => ({
locationUuid: loc.locationUuid,
locationName: loc.locationName,
enableDescendants: false,
})),
permanent: data.permanent,
enabled: data.enabled,
activeFrom: data.dateRange.activeFrom,
activeTo: data.dateRange.activeTo,
operationTypes: hasOperationTypes
? data.stockOperation.map((op) => ({
operationTypeUuid: op.operationTypeUuid,
operationTypeName: op.operationTypeName,
}))
: [],
activeFrom: data.dateRange?.activeFrom,
activeTo: data.dateRange?.activeTo,
operationTypes: data.stockOperation?.map((op) => ({
operationTypeUuid: op.operationTypeUuid,
operationTypeName: op.operationTypeName,
})),
};

if (!hasValidRoleConditions && userRoleScopePayload.locations.length === 0) {
if (!hasValidRoleConditions && userRoleScopePayload.locations?.length === 0) {
return null;
}

Expand Down
2 changes: 1 addition & 1 deletion packages/esm-billing-app/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@
"finalDiagnosis": "Final Diagnosis",
"formTitle": "Fill in the form details",
"generatedMessage": "The invoice has been electronically generated and is a valid document. It was created by {{userName}} on {{date}} at {{time}}",
"HIEVerificationFailure": "HIE verification failure",
"home": "Home",
"identifier": "Identifier",
"inactive": "Inactive",
Expand Down Expand Up @@ -200,7 +201,6 @@
"paymentPoints": "Payment Points",
"payments": "Payments",
"paymentType": "Payment Type",
"pendingHIEVerification": "Pending HIE verification",
"Phone Number": "Phone Number",
"pickLabRequest": "Pick Lab Request",
"policyNumber": "Policy number",
Expand Down

0 comments on commit cc7612b

Please sign in to comment.