-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' into feature/RDI-Access-change-for-retrieving-…
…data-from-Kobo-NEW
- Loading branch information
Showing
47 changed files
with
736 additions
and
78 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
src/frontend/src/components/grievances/EditPeopleDataChange/CurrentValue.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import { Grid } from '@mui/material'; | ||
import { useTranslation } from 'react-i18next'; | ||
import { useLocation } from 'react-router-dom'; | ||
import { AllAddIndividualFieldsQuery } from '@generated/graphql'; | ||
import { LabelizedField } from '@core/LabelizedField'; | ||
import { GrievanceFlexFieldPhotoModal } from '../GrievancesPhotoModals/GrievanceFlexFieldPhotoModal'; | ||
import { GrievanceFlexFieldPhotoModalNewIndividual } from '../GrievancesPhotoModals/GrievanceFlexFieldPhotoModalNewIndividual'; | ||
import { ReactElement } from 'react'; | ||
|
||
export interface CurrentValueProps { | ||
field: AllAddIndividualFieldsQuery['allAddIndividualsFieldsAttributes'][number]; | ||
value; | ||
values; | ||
} | ||
|
||
export function CurrentValue({ | ||
field, | ||
value, | ||
values, | ||
}: CurrentValueProps): ReactElement { | ||
const location = useLocation(); | ||
const isNewTicket = location.pathname.indexOf('new-ticket') !== -1; | ||
|
||
const { t } = useTranslation(); | ||
let displayValue = value; | ||
switch (field?.type) { | ||
case 'SELECT_ONE': | ||
displayValue = | ||
field.choices.find((item) => item.value === value)?.labelEn || '-'; | ||
break; | ||
case 'SELECT_MANY': | ||
displayValue = | ||
field.choices.find((item) => item.value === value)?.labelEn || '-'; | ||
if (value instanceof Array) { | ||
displayValue = value | ||
.map( | ||
(choice) => | ||
field.choices.find((item) => item.value === choice)?.labelEn || | ||
'-', | ||
) | ||
.join(', '); | ||
} | ||
break; | ||
case 'BOOL': | ||
/* eslint-disable-next-line no-nested-ternary */ | ||
displayValue = value === null ? '-' : value ? t('Yes') : t('No'); | ||
break; | ||
case 'IMAGE': | ||
return isNewTicket ? ( | ||
<Grid item xs={3}> | ||
<GrievanceFlexFieldPhotoModalNewIndividual | ||
flexField={field} | ||
individualId={values?.selectedIndividual?.id || null} | ||
/> | ||
</Grid> | ||
) : ( | ||
<Grid item xs={3}> | ||
<GrievanceFlexFieldPhotoModal isCurrent isIndividual field={field} /> | ||
</Grid> | ||
); | ||
default: | ||
displayValue = value; | ||
} | ||
return ( | ||
<Grid item xs={3}> | ||
<LabelizedField label="Current Value" value={displayValue} /> | ||
</Grid> | ||
); | ||
} |
127 changes: 127 additions & 0 deletions
127
src/frontend/src/components/grievances/EditPeopleDataChange/EditPeopleDataChange.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
import { Button, Grid, Typography } from '@mui/material'; | ||
import { AddCircleOutline } from '@mui/icons-material'; | ||
import { useLocation } from 'react-router-dom'; | ||
import { FieldArray } from 'formik'; | ||
import { ReactElement, useEffect } from 'react'; | ||
import { useTranslation } from 'react-i18next'; | ||
import styled from 'styled-components'; | ||
import { | ||
AllIndividualsQuery, | ||
useAllEditPeopleFieldsQuery, | ||
useIndividualLazyQuery, | ||
} from '@generated/graphql'; | ||
import { LoadingComponent } from '@core/LoadingComponent'; | ||
import { Title } from '@core/Title'; | ||
import { EditPeopleDataChangeFieldRow } from './EditPeopleDataChangeFieldRow'; | ||
|
||
const BoxWithBorders = styled.div` | ||
border-bottom: 1px solid ${({ theme }) => theme.hctPalette.lighterGray}; | ||
padding: 15px 0; | ||
`; | ||
|
||
export interface EditPeopleDataChangeProps { | ||
values; | ||
setFieldValue; | ||
form; | ||
field; | ||
} | ||
|
||
export function EditPeopleDataChange({ | ||
values, | ||
setFieldValue, | ||
}: EditPeopleDataChangeProps): ReactElement { | ||
const { t } = useTranslation(); | ||
const location = useLocation(); | ||
const isEditTicket = location.pathname.indexOf('edit-ticket') !== -1; | ||
const individual: AllIndividualsQuery['allIndividuals']['edges'][number]['node'] = | ||
values.selectedIndividual; | ||
const { data: editPeopleFieldsData, loading: editPeopleFieldsLoading } = | ||
useAllEditPeopleFieldsQuery(); | ||
|
||
const [ | ||
getIndividual, | ||
{ data: fullIndividual, loading: fullIndividualLoading }, | ||
] = useIndividualLazyQuery({ variables: { id: individual?.id } }); | ||
|
||
useEffect(() => { | ||
if (individual) { | ||
getIndividual(); | ||
} | ||
// eslint-disable-next-line react-hooks/exhaustive-deps | ||
}, [values.selectedIndividual]); | ||
|
||
useEffect(() => { | ||
if ( | ||
!values.individualDataUpdateFields || | ||
values.individualDataUpdateFields.length === 0 | ||
) { | ||
setFieldValue('individualDataUpdateFields', [ | ||
{ fieldName: null, fieldValue: null }, | ||
]); | ||
} | ||
// eslint-disable-next-line react-hooks/exhaustive-deps | ||
}, []); | ||
if (!individual) { | ||
return <div>{t('You have to select an individual earlier')}</div>; | ||
} | ||
if ( | ||
editPeopleFieldsLoading || | ||
fullIndividualLoading || | ||
editPeopleFieldsLoading || | ||
!fullIndividual | ||
) { | ||
return <LoadingComponent />; | ||
} | ||
const notAvailableItems = (values.individualDataUpdateFields || []).map( | ||
(fieldItem) => fieldItem.fieldName, | ||
); | ||
|
||
return ( | ||
<> | ||
{!isEditTicket && ( | ||
<BoxWithBorders> | ||
<Title> | ||
<Typography variant="h6">{t('Bio Data')}</Typography> | ||
</Title> | ||
<Grid container spacing={3}> | ||
<FieldArray | ||
name="individualDataUpdateFields" | ||
render={(arrayHelpers) => ( | ||
<> | ||
{values.individualDataUpdateFields.map((item, index) => ( | ||
<EditPeopleDataChangeFieldRow | ||
// eslint-disable-next-line react/no-array-index-key | ||
key={`${index}-${item?.fieldName}`} | ||
itemValue={item} | ||
index={index} | ||
individual={fullIndividual.individual} | ||
fields={ | ||
editPeopleFieldsData.allEditPeopleFieldsAttributes | ||
} | ||
notAvailableFields={notAvailableItems} | ||
onDelete={() => arrayHelpers.remove(index)} | ||
values={values} | ||
/> | ||
))} | ||
<Grid item xs={4}> | ||
<Button | ||
color="primary" | ||
onClick={() => { | ||
arrayHelpers.push({ fieldName: null, fieldValue: '' }); | ||
}} | ||
startIcon={<AddCircleOutline />} | ||
data-cy="button-add-new-field" | ||
disabled={isEditTicket} | ||
> | ||
{t('Add new field')} | ||
</Button> | ||
</Grid> | ||
</> | ||
)} | ||
/> | ||
</Grid> | ||
</BoxWithBorders> | ||
)} | ||
</> | ||
); | ||
} |
110 changes: 110 additions & 0 deletions
110
src/frontend/src/components/grievances/EditPeopleDataChange/EditPeopleDataChangeField.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
import { Grid } from '@mui/material'; | ||
import { Field } from 'formik'; | ||
import { useLocation } from 'react-router-dom'; | ||
import CalendarTodayRoundedIcon from '@mui/icons-material/CalendarTodayRounded'; | ||
import { FormikDateField } from '@shared/Formik/FormikDateField'; | ||
import { FormikDecimalField } from '@shared/Formik/FormikDecimalField'; | ||
import { FormikFileField } from '@shared/Formik/FormikFileField'; | ||
import { FormikSelectField } from '@shared/Formik/FormikSelectField'; | ||
import { FormikTextField } from '@shared/Formik/FormikTextField'; | ||
import { AllAddIndividualFieldsQuery } from '@generated/graphql'; | ||
import { FormikBoolFieldGrievances } from '../FormikBoolFieldGrievances'; | ||
import { GrievanceFlexFieldPhotoModalEditable } from '../GrievancesPhotoModals/GrievanceFlexFieldPhotoModalEditable'; | ||
import { ReactElement } from 'react'; | ||
|
||
export interface EditPeopleDataChangeFieldProps { | ||
field: AllAddIndividualFieldsQuery['allAddIndividualsFieldsAttributes'][number]; | ||
name: string; | ||
} | ||
export const EditPeopleDataChangeField = ({ | ||
name, | ||
field, | ||
}: EditPeopleDataChangeFieldProps): ReactElement => { | ||
const location = useLocation(); | ||
const isNewTicket = location.pathname.indexOf('new-ticket') !== -1; | ||
const isEditTicket = location.pathname.indexOf('edit-ticket') !== -1; | ||
|
||
let fieldProps; | ||
if (!field) return null; | ||
|
||
switch (field.type) { | ||
case 'DECIMAL': | ||
fieldProps = { | ||
fullWidth: true, | ||
component: FormikDecimalField, | ||
}; | ||
break; | ||
case 'INTEGER': | ||
fieldProps = { | ||
component: FormikTextField, | ||
type: 'number', | ||
}; | ||
break; | ||
case 'STRING': | ||
fieldProps = { | ||
fullWidth: true, | ||
component: FormikTextField, | ||
}; | ||
break; | ||
case 'SELECT_ONE': | ||
fieldProps = { | ||
choices: field.choices, | ||
fullWidth: true, | ||
component: FormikSelectField, | ||
}; | ||
break; | ||
case 'SELECT_MANY': | ||
fieldProps = { | ||
choices: field.choices, | ||
fullWidth: true, | ||
component: FormikSelectField, | ||
multiple: true, | ||
}; | ||
break; | ||
case 'SELECT_MULTIPLE': | ||
fieldProps = { | ||
choices: field.choices, | ||
fullWidth: true, | ||
component: FormikSelectField, | ||
}; | ||
break; | ||
case 'DATE': | ||
fieldProps = { | ||
component: FormikDateField, | ||
fullWidth: true, | ||
decoratorEnd: <CalendarTodayRoundedIcon color="disabled" />, | ||
}; | ||
break; | ||
|
||
case 'BOOL': | ||
fieldProps = { | ||
component: FormikBoolFieldGrievances, | ||
required: field.required, | ||
}; | ||
break; | ||
case 'IMAGE': | ||
fieldProps = { | ||
component: isNewTicket | ||
? FormikFileField | ||
: GrievanceFlexFieldPhotoModalEditable, | ||
flexField: field, | ||
isIndividual: true, | ||
}; | ||
break; | ||
default: | ||
fieldProps = {}; | ||
} | ||
return ( | ||
<Grid item xs={4}> | ||
<Field | ||
name={name} | ||
variant="outlined" | ||
label={field.labelEn} | ||
required={field.required} | ||
data-cy={`input-individual-data-${field.labelEn}`} | ||
disabled={isEditTicket} | ||
{...fieldProps} | ||
/> | ||
</Grid> | ||
); | ||
}; |
Oops, something went wrong.