Skip to content

Commit

Permalink
Fix old referral form bug
Browse files Browse the repository at this point in the history
  • Loading branch information
AdJez committed Dec 18, 2024
1 parent e6b723a commit 2ea8390
Showing 1 changed file with 33 additions and 17 deletions.
50 changes: 33 additions & 17 deletions src/frontend/js/components/ReferralForm/OldReferralForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { Spinner } from 'components/Spinner';
import { useCurrentUser } from 'data/useCurrentUser';
import { Referral, RequesterUnitType } from 'types';
import { sendForm } from 'utils/sendForm';
import { getUserFullname } from 'utils/user';
import { getUserFullname, isFromCentralUnit } from 'utils/user';

import { AttachmentsField } from './AttachmentsField';
import { ContextField } from './ContextField';
Expand Down Expand Up @@ -199,9 +199,9 @@ export const OldReferralForm: React.FC = () => {
// Add all textual fields to the form directly
...Object.entries(fields)
.filter(([key]) => !['files', 'urgency_level'].includes(key))
.map(
([key, content]) => [key, content.data] as [string, string],
),
.map(([key, content]) => {
return [key, content?.data] as [string, string];
}),
['urgency_level', String(fields.urgency_level.data.id)],
],
url: `/api/referrals/${referral!.id}/send/`,
Expand Down Expand Up @@ -253,6 +253,20 @@ export const OldReferralForm: React.FC = () => {
return subscription.unsubscribe;
}, [service]);

useEffect(() => {
if (!isFromCentralUnit(currentUser)) {
send({
payload: {
clean: state.matches('cleaned.true'),
data: RequesterUnitType.DECENTRALISED_UNIT,
valid: state.matches('validation.valid'),
},
fieldName: 'requester_unit_type',
type: 'UPDATE',
});
}
}, [currentUser, send]);

switch (status) {
case 'error':
return <GenericErrorMessage />;
Expand Down Expand Up @@ -321,19 +335,21 @@ export const OldReferralForm: React.FC = () => {
</Spinner>
)}

<RequesterUnitTypeField
requesterUnitType={referral?.requester_unit_type}
sendToParent={send}
cleanAllFields={cleanAllFields}
>
{showRequesterUnitContactField && (
<RequesterUnitContactField
requesterUnitContact={referral?.requester_unit_contact}
sendToParent={send}
cleanAllFields={cleanAllFields}
/>
)}
</RequesterUnitTypeField>
{referral && (
<RequesterUnitTypeField
requesterUnitType={referral.requester_unit_type}
sendToParent={send}
cleanAllFields={cleanAllFields}
>
{showRequesterUnitContactField && (
<RequesterUnitContactField
requesterUnitContact={referral.requester_unit_contact}
sendToParent={send}
cleanAllFields={cleanAllFields}
/>
)}
</RequesterUnitTypeField>
)}

<TopicField
topicValue={referral?.topic}
Expand Down

0 comments on commit 2ea8390

Please sign in to comment.