Skip to content

Commit

Permalink
CM-698: add new roles to group individuals
Browse files Browse the repository at this point in the history
  • Loading branch information
jdolkowski committed May 28, 2024
1 parent f190177 commit 604f14c
Show file tree
Hide file tree
Showing 7 changed files with 74 additions and 12 deletions.
4 changes: 3 additions & 1 deletion src/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import {
formatMutation,
formatGQLString,
graphqlWithVariables,
useModulesManager,
prepareMutation,
} from '@openimis/fe-core';
import { ACTION_TYPE } from './reducer';
Expand Down Expand Up @@ -64,6 +63,7 @@ const GROUP_INDIVIDUAL_FULL_PROJECTION = [
'individual {id, firstName, lastName, dob}',
'group {id, code}',
'role',
'recipientType',
'isDeleted',
'dateCreated',
'dateUpdated',
Expand All @@ -87,6 +87,7 @@ const GROUP_INDIVIDUAL_HISTORY_FULL_PROJECTION = [
'individual {id, firstName, lastName, dob}',
'group {id}',
'role',
'recipientType',
'isDeleted',
'dateCreated',
'dateUpdated',
Expand Down Expand Up @@ -256,6 +257,7 @@ function formatGroupIndividualGQL(groupIndividual) {
return `
${groupIndividual?.id ? `id: "${groupIndividual.id}"` : ''}
${groupIndividual?.role ? `role: ${groupIndividual.role}` : ''}
${groupIndividual?.recipientType ? `recipientType: ${groupIndividual.recipientType}` : ''}
${groupIndividual?.individual.id ? `individualId: "${groupIndividual.individual.id}"` : ''}
${groupIndividual?.group.id ? `groupId: "${groupIndividual.group.id}"` : ''}`;
}
Expand Down
30 changes: 26 additions & 4 deletions src/components/GroupIndividualSearcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import {
import GroupIndividualFilter from './GroupIndividualFilter';
import GroupIndividualRolePicker from '../pickers/GroupIndividualRolePicker';
import GroupChangeDialog from './GroupChangeDialog';
import GroupIndividualRecipientTypePicker from '../pickers/GroupIndividualRecipientTypePicker';

function GroupIndividualSearcher({
intl,
Expand Down Expand Up @@ -136,6 +137,7 @@ function GroupIndividualSearcher({
'individual.lastName',
'individual.dob',
'groupIndividual.individual.role',
'groupIndividual.individual.recipientType',
'emptyLabel',
];
if (rights.includes(RIGHT_GROUP_INDIVIDUAL_UPDATE)) {
Expand All @@ -147,15 +149,15 @@ function GroupIndividualSearcher({
const addUpdatedGroupIndividual = (groupIndividual, role) => {
setUpdatedGroupIndividuals((prevState) => {
const updatedBeneficiaryExists = prevState.some(
(item) => item.id === groupIndividual.id && item.role === role,
(item) => item.id === groupIndividual.id && (item.role === role || item.recipient_type),
);

if (!updatedBeneficiaryExists) {
return [...prevState, groupIndividual];
}

return prevState.filter(
(item) => !(item.id === groupIndividual.id && item.role === role),
(item) => !(item.id === groupIndividual.id && (item.role === role || item.recipient_type)),
);
});
};
Expand All @@ -174,6 +176,20 @@ function GroupIndividualSearcher({
}
};

const handleRecipientTypeOnChange = (groupIndividual, recipientType) => {
if (groupIndividual && recipientType) {
addUpdatedGroupIndividual(groupIndividual, recipientType);
const editedGroupIndividual = { ...groupIndividual, recipientType };
updateGroupIndividual(
editedGroupIndividual,
formatMessageWithValues(intl, 'individual', 'groupIndividual.update.mutationLabel', {
id: editedGroupIndividual?.individual?.id,
}),
);
setRefetch(editedGroupIndividual?.individual?.id);
}
};

const handleGroupChange = (groupIndividual) => {
setIsChangeGroupModalOpen(true);
setEditedGroupIndividual(groupIndividual);
Expand All @@ -190,7 +206,7 @@ function GroupIndividualSearcher({
const updateIndividual = {
...editedGroupIndividual,
group: groupToBeChanged,
role: GROUP_INDIVIDUAL_ROLES.RECIPIENT,
role: GROUP_INDIVIDUAL_ROLES.HEAD,
};
updateGroupIndividual(
updateIndividual,
Expand All @@ -214,11 +230,17 @@ function GroupIndividualSearcher({
(groupIndividual) => (rights.includes(RIGHT_GROUP_INDIVIDUAL_UPDATE) && !isRowDeleted(groupIndividual) ? (
<GroupIndividualRolePicker
withLabel={false}
withNull={false}
value={groupIndividual.role}
onChange={(role) => handleRoleOnChange(groupIndividual, role)}
/>
) : groupIndividual.role),
(groupIndividual) => (rights.includes(RIGHT_GROUP_INDIVIDUAL_UPDATE) && !isRowDeleted(groupIndividual) ? (
<GroupIndividualRecipientTypePicker
withLabel={false}
value={groupIndividual.recipientType}
onChange={(recipientType) => handleRecipientTypeOnChange(groupIndividual, recipientType)}
/>
) : groupIndividual.recipientType),
(groupIndividual) => (rights.includes(RIGHT_GROUP_INDIVIDUAL_UPDATE) ? (
(
<Tooltip title={formatMessage(intl, 'individual', 'changeGroupButtonTooltip')}>
Expand Down
6 changes: 4 additions & 2 deletions src/components/tasks/GroupImportTasks.js
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,10 @@ function GroupUploadTaskDisplay({
items.push((pending) => {
if (Object.prototype.hasOwnProperty.call(pending, key)) {
const value = pending[key];
// Check if the value is an array and join it into a comma-separated string
return Array.isArray(value) ? value.join(', ') : value;
if (Array.isArray(value)) {
return value.map((item) => JSON.stringify(item)).join(', ');
}
return JSON.stringify(value);
}
return '-';
});
Expand Down
2 changes: 2 additions & 0 deletions src/components/tasks/GroupIndividualUpdateTasks.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@ const GroupIndividualUpdateTaskTableHeaders = () => [
<FormattedMessage module="individual" id="groupIndividual.individual.groupId" />,
<FormattedMessage module="individual" id="groupIndividual.individual.individualId" />,
<FormattedMessage module="individual" id="groupIndividual.individual.role" />,
<FormattedMessage module="individual" id="groupIndividual.individual.recipientType" />,
];

const GroupIndividualUpdateTaskItemFormatters = () => [
(groupIndividual) => groupIndividual?.group ?? groupIndividual?.group_id,
(groupIndividual) => groupIndividual?.id,
(groupIndividual) => groupIndividual?.role,
(groupIndividual) => groupIndividual?.recipient_type,
];

export { GroupIndividualUpdateTaskTableHeaders, GroupIndividualUpdateTaskItemFormatters };
27 changes: 25 additions & 2 deletions src/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,34 @@ export const BENEFICIARY_STATUS = {

export const GROUP_INDIVIDUAL_ROLES = {
HEAD: 'HEAD',
RECIPIENT: 'RECIPIENT',
SPOUSE: 'SPOUSE',
SON: 'SON',
DAUGHTER: 'DAUGHTER',
GRANDFATHER: 'GRANDFATHER',
GRANDMOTHER: 'GRANDMOTHER',
MOTHER: 'MOTHER',
FATHER: 'FATHER',
};

export const RECIPIENT_TYPE = {
PRIMARY: 'PRIMARY',
SECONDARY: 'SECONDARY',
};

export const GROUP_INDIVIDUAL_ROLES_LIST = [
GROUP_INDIVIDUAL_ROLES.HEAD, GROUP_INDIVIDUAL_ROLES.RECIPIENT,
GROUP_INDIVIDUAL_ROLES.HEAD,
GROUP_INDIVIDUAL_ROLES.SPOUSE,
GROUP_INDIVIDUAL_ROLES.SON,
GROUP_INDIVIDUAL_ROLES.DAUGHTER,
GROUP_INDIVIDUAL_ROLES.GRANDFATHER,
GROUP_INDIVIDUAL_ROLES.GRANDMOTHER,
GROUP_INDIVIDUAL_ROLES.MOTHER,
GROUP_INDIVIDUAL_ROLES.FATHER,
];

export const RECIPIENT_TYPE_LIST = [
RECIPIENT_TYPE.PRIMARY,
RECIPIENT_TYPE.SECONDARY,
];

export const BENEFIT_PLAN_LABEL = 'BenefitPlan';
Expand Down
4 changes: 2 additions & 2 deletions src/pickers/GroupIndividualRolePicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {

function GroupIndividualRolePicker(props) {
const {
required, withNull, readOnly, onChange, value, nullLabel, withLabel,
required, readOnly, onChange, value, nullLabel, withLabel,
} = props;
return (
<ConstantBasedPicker
Expand All @@ -17,7 +17,7 @@ function GroupIndividualRolePicker(props) {
value={value}
required={required}
readOnly={readOnly}
withNull={withNull}
withNull
nullLabel={nullLabel}
withLabel={withLabel}
/>
Expand Down
13 changes: 12 additions & 1 deletion src/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@
"groupIndividual": {
"individual": {
"role": "Role",
"recipientType": "Recipient Type",
"groupId": "Group ID",
"individualId": "Individual ID"
},
Expand All @@ -225,7 +226,17 @@
}
},
"groupIndividualRolePicker.HEAD": "HEAD",
"groupIndividualRolePicker.RECIPIENT": "RECIPIENT",
"groupIndividualRolePicker.SPOUSE": "SPOUSE",
"groupIndividualRolePicker.SON": "SON",
"groupIndividualRolePicker.DAUGHTER": "DAUGHTER",
"groupIndividualRolePicker.GRANDFATHER": "GRANDFATHER",
"groupIndividualRolePicker.GRANDMOTHER": "GRANDMOTHER",
"groupIndividualRolePicker.MOTHER": "MOTHER",
"groupIndividualRolePicker.FATHER": "FATHER",
"groupIndividualRolePicker.null": " ",
"groupIndividualRecipientTypePicker.PRIMARY": "PRIMARY",
"groupIndividualRecipientTypePicker.SECONDARY": "SECONDARY",
"groupIndividualRecipientTypePicker.null": " ",
"groupIndividualRolePicker": "Role",
"dateJoined": "Joining Date",
"statusOfMembership": "Status Of Membership"
Expand Down

0 comments on commit 604f14c

Please sign in to comment.