diff --git a/frontend/src/interfaces/index.ts b/frontend/src/interfaces/index.ts index 06b9f45d65e7a1e7aa5ac1cbe32449e4b1622beb..9ebcefd5d2239fb2dd46ae9c47f728f0f8fd56cf 100644 --- a/frontend/src/interfaces/index.ts +++ b/frontend/src/interfaces/index.ts @@ -52,6 +52,7 @@ export type Role = { end_date: Date max_days: number contact_person_unit: string | null + comments: string | null } export type FetchedRole = { @@ -64,6 +65,7 @@ export type FetchedRole = { end_date: string max_days: number contact_person_unit: string | null + comments: string | null } export type ConsentType = { diff --git a/frontend/src/routes/sponsor/guest/guestRoleInfo/index.tsx b/frontend/src/routes/sponsor/guest/guestRoleInfo/index.tsx index d06a638d53280e7f1a981579d83aa092ef74ae7a..7dc1425398bf39f3df45607b18fab3617adc2125 100644 --- a/frontend/src/routes/sponsor/guest/guestRoleInfo/index.tsx +++ b/frontend/src/routes/sponsor/guest/guestRoleInfo/index.tsx @@ -16,6 +16,7 @@ import SponsorInfoButtons from 'routes/components/sponsorInfoButtons' import { DatePicker } from '@mui/lab' import { Controller, SubmitHandler, useForm } from 'react-hook-form' import { getRoleName, getRoleOuName, submitJsonOpts } from 'utils' +import { useFeatureContext } from 'contexts/featureContext' interface GuestRoleInfoProps { guest: Guest @@ -95,6 +96,7 @@ const TableContainer = styled(TableContainerMui)({ export default function GuestRoleInfo({ guest }: GuestRoleInfoProps) { const { pid, id } = useParams<GuestRoleInfoParams>() const [t] = useTranslation('common') + const { displayContactAtUnit, displayComment } = useFeatureContext() const [role, setRole] = useState<Role>({ id: '', name_nb: '', @@ -105,6 +107,7 @@ export default function GuestRoleInfo({ guest }: GuestRoleInfoProps) { end_date: new Date(), max_days: 365, contact_person_unit: null, + comments: null, }) // Find the role info relevant for this page const getRoleInfo = () => { @@ -232,13 +235,24 @@ export default function GuestRoleInfo({ guest }: GuestRoleInfoProps) { <TableCell align="left">{getRoleOuName(role)}</TableCell> <TableCell align="left" /> </TableRow> - <TableRow> - <TableCell align="left" sx={{ fontWeight: 'bold' }}> - {t('sponsor.contactPerson')} - </TableCell> - <TableCell align="left">{role.contact_person_unit}</TableCell> - <TableCell align="left" /> - </TableRow> + {displayContactAtUnit && ( + <TableRow> + <TableCell align="left" sx={{ fontWeight: 'bold' }}> + {t('sponsor.contactPerson')} + </TableCell> + <TableCell align="left">{role.contact_person_unit}</TableCell> + <TableCell align="left" /> + </TableRow> + )} + {displayComment && ( + <TableRow> + <TableCell align="left" sx={{ fontWeight: 'bold' }}> + {t('input.comment')} + </TableCell> + <TableCell align="left">{role.comments}</TableCell> + <TableCell align="left" /> + </TableRow> + )} </TableBody> </Table> </TableContainer> diff --git a/frontend/src/routes/sponsor/guest/newGuestRole/index.tsx b/frontend/src/routes/sponsor/guest/newGuestRole/index.tsx index 2916a1ef2397af8b626a50a268b310c1e3426e9c..ab141683b36243d3a9cd8bb16754ce32e0a09806 100644 --- a/frontend/src/routes/sponsor/guest/newGuestRole/index.tsx +++ b/frontend/src/routes/sponsor/guest/newGuestRole/index.tsx @@ -25,6 +25,7 @@ import { useTranslation } from 'react-i18next' import { Link, useHistory, useParams } from 'react-router-dom' import SponsorInfoButtons from 'routes/components/sponsorInfoButtons' import { submitJsonOpts } from 'utils' +import { useFeatureContext } from 'contexts/featureContext' type AddRoleFormData = { orgunit: number @@ -104,6 +105,7 @@ function NewGuestRole({ guest, reloadGuestInfo }: NewGuestRoleProps) { setValue, getValues, } = useForm<AddRoleFormData>() + const { displayContactAtUnit, displayComment } = useFeatureContext() const { pid } = useParams<GuestInfoParams>() const history = useHistory() @@ -279,20 +281,25 @@ function NewGuestRole({ guest, reloadGuestInfo }: NewGuestRoleProps) { /> )} /> - <TextField - id="contact" - label={t('input.contactPersonUnit')} - multiline - rows={5} - {...register('contact_person_unit')} - /> - <TextField - id="comments" - label={t('input.comment')} - multiline - rows={5} - {...register('comments')} - /> + {displayContactAtUnit && ( + <TextField + id="contact" + label={t('input.contactPersonUnit')} + multiline + rows={5} + {...register('contact_person_unit')} + /> + )} + {displayComment && ( + <TextField + id="comments" + label={t('input.comment')} + multiline + rows={5} + {...register('comments')} + /> + )} + <FormControlLabel control={ <Checkbox diff --git a/frontend/src/utils/index.ts b/frontend/src/utils/index.ts index cb2ffe7dbc882fc26f16537950bc5d599d8b7da2..f045820a16de62626651f877b5828f0730b800ac 100644 --- a/frontend/src/utils/index.ts +++ b/frontend/src/utils/index.ts @@ -147,6 +147,7 @@ export function parseRole(role: FetchedRole): Role { end_date: parseISO(role.end_date), max_days: role.max_days, contact_person_unit: role.contact_person_unit, + comments: role.comments, } } diff --git a/greg/api/serializers/role.py b/greg/api/serializers/role.py index 99ad317dc7e312854f9c2b9e9e0ea4267dd28b96..acdb7b4a0151fd5e2b86d727313897995f6eef5a 100644 --- a/greg/api/serializers/role.py +++ b/greg/api/serializers/role.py @@ -78,6 +78,7 @@ class SpecialRoleSerializer(serializers.ModelSerializer): "end_date", "max_days", "contact_person_unit", + "comments", ] read_only_fields = [ "contact_person_unit",