Skip to content

Commit

Permalink
fix(persons): update person disqualification flow
Browse files Browse the repository at this point in the history
  • Loading branch information
rhahao authored Dec 16, 2024
1 parent b82e4bf commit 7bbe2d1
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 26 deletions.
10 changes: 2 additions & 8 deletions src/features/persons/assignment_group/index.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import AssignmentsCheckList from '@components/assignments_checklist';
import Checkbox from '@components/checkbox';
import { AssignmentGroupType } from './index.types';
import useAssignmentGroup from './useAssignmentGroup';
import AssignmentsCheckList from '@components/assignments_checklist';
import Checkbox from '@components/checkbox';
import Tooltip from '@components/tooltip';
import { useBreakpoints } from '@hooks/index';

const AssignmentGroup = ({
header,
Expand All @@ -26,16 +25,11 @@ const AssignmentGroup = ({
getTooltipsForAssignmentTitles,
} = useAssignmentGroup(male);

const { tablet600Down } = useBreakpoints();

return (
<Tooltip
followCursor
title={getTooltipsForAssignmentTitles(id, items)}
show={isMinistryDisabled(id, items) || isDisabledByGender(id)}
sx={{
width: tablet600Down ? '100%' : 'calc(50% - 16px)',
}}
>
<AssignmentsCheckList
sx={sx}
Expand Down
35 changes: 19 additions & 16 deletions src/features/persons/assignments/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Box } from '@mui/material';
import { Box, Grid2 as Grid } from '@mui/material';
import { useAppTranslation, useCurrentUser } from '@hooks/index';
import useAssignments from './useAssignments';
import AssignmentGroup from '../assignment_group';
Expand Down Expand Up @@ -32,23 +32,26 @@ const PersonAssignments = () => {
>
<Typography className="h2">{t('tr_assignments')}</Typography>

<Box sx={{ display: 'flex', gap: '16px', flexWrap: 'wrap' }}>
<Grid container spacing={2}>
{assignments.map((assignment) => (
<AssignmentGroup
key={assignment.id}
readOnly={!isPersonEditor}
id={assignment.id}
header={assignment.header}
color={assignment.color}
items={assignment.items}
onHeaderChange={handleToggleGroup}
onItemChange={handleToggleAssignment}
checkedItems={checkedItems}
male={male}
disqualified={disqualified}
/>
<Grid key={assignment.id} size={{ mobile: 12, laptop: 6 }}>
<AssignmentGroup
sx={{ width: '100%' }}
key={assignment.id}
readOnly={!isPersonEditor}
id={assignment.id}
header={assignment.header}
color={assignment.color}
items={assignment.items}
onHeaderChange={handleToggleGroup}
onItemChange={handleToggleAssignment}
checkedItems={checkedItems}
male={male}
disqualified={disqualified}
/>
</Grid>
))}
</Box>
</Grid>
</Box>
);
};
Expand Down
4 changes: 4 additions & 0 deletions src/features/persons/button_actions/useButtonActions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,17 @@ const useButtonActions = () => {
const handleDisqualifyConfirm = async () => {
try {
const newPerson = structuredClone(person);

newPerson.person_data.disqualified = {
value: true,
updatedAt: new Date().toISOString(),
};

personAssignmentsRemove(newPerson);

await dbPersonsSave(newPerson);

setIsDisqualify(false);
} catch (error) {
await displaySnackNotification({
header: getMessageByCode('error_app_generic-title'),
Expand Down
3 changes: 2 additions & 1 deletion src/locales/en/congregation.json
Original file line number Diff line number Diff line change
Expand Up @@ -453,5 +453,6 @@
"tr_importDataConfirm": "Confirm importing new data",
"tr_importDataConfirmDesc": "Select the data you want to import to replace your records in Organized",
"tr_importDataCompleted": "Import completed",
"tr_importDataCompletedDesc": "Your data has been imported successfully. Organized app will now reload."
"tr_importDataCompletedDesc": "Your data has been imported successfully. Organized app will now reload.",
"tr_markDisqualifiedTitle": "Mark as disqualified"
}
2 changes: 1 addition & 1 deletion src/services/app/persons.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ const personEndActivePrivileges = (person: PersonType) => {

export const personAssignmentsRemove = (person: PersonType) => {
for (const assignment of person.person_data.assignments) {
if (assignment._deleted === false) {
if (!assignment._deleted) {
assignment._deleted = true;
assignment.updatedAt = new Date().toISOString();
}
Expand Down

0 comments on commit 7bbe2d1

Please sign in to comment.