Skip to content

Commit 3d65218

Browse files
committed
WIP
1 parent b76e711 commit 3d65218

File tree

4 files changed

+43
-17
lines changed

4 files changed

+43
-17
lines changed

src/layout/SigneeList/api.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,17 @@ export type SigneeState = z.infer<typeof signeeStateSchema>;
3333

3434
export const signingQueries = {
3535
all: ['signing'] as const,
36-
signeeList: (partyId: string | undefined, instanceGuid: string | undefined, taskId: string | undefined) =>
36+
signeeList: (
37+
instanceOwnerPartyId: string | undefined,
38+
instanceGuid: string | undefined,
39+
taskId: string | undefined,
40+
) =>
3741
queryOptions({
38-
queryKey: [...signingQueries.all, 'signeeList', partyId, instanceGuid, taskId],
39-
queryFn: partyId && instanceGuid && taskId ? () => fetchSigneeList(partyId, instanceGuid) : skipToken,
42+
queryKey: [...signingQueries.all, 'signeeList', instanceOwnerPartyId, instanceGuid, taskId],
43+
queryFn:
44+
instanceOwnerPartyId && instanceGuid && taskId
45+
? () => fetchSigneeList(instanceOwnerPartyId, instanceGuid)
46+
: skipToken,
4047
refetchInterval: 1000 * 60, // 1 minute
4148
refetchOnMount: 'always',
4249
}),

src/layout/SigningActions/OnBehalfOfChooser.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,20 @@ import { RequiredIndicator } from 'src/components/form/RequiredIndicator';
99
import { Lang } from 'src/features/language/Lang';
1010
import { useLanguage } from 'src/features/language/useLanguage';
1111
import { type SigneeState } from 'src/layout/SigneeList/api';
12-
import type { AuthorizedOrganizationDetails } from 'src/layout/SigningActions/api';
12+
import type { AuthorizedOrganizationDetails, OnBehalfOf } from 'src/layout/SigningActions/api';
1313

1414
interface OnBehalfOfChooserProps {
1515
currentUserSignee: SigneeState | undefined;
1616
authorizedOrganizationDetails: AuthorizedOrganizationDetails['organizations'];
17-
onBehalfOfOrg: string | null;
17+
onBehalfOf: OnBehalfOf | null;
1818
onChange: (event: ChangeEvent<HTMLInputElement>) => void;
1919
error: boolean;
2020
}
2121

2222
export const OnBehalfOfChooser = ({
2323
currentUserSignee,
2424
authorizedOrganizationDetails,
25-
onBehalfOfOrg,
25+
onBehalfOf,
2626
onChange,
2727
error = false,
2828
}: Readonly<OnBehalfOfChooserProps>) => {
@@ -42,18 +42,18 @@ export const OnBehalfOfChooser = ({
4242
name='onBehalfOf'
4343
key={currentUserSignee.partyId}
4444
onChange={onChange}
45-
checked={onBehalfOfOrg === ''}
45+
checked={onBehalfOf?.orgNoOrSsn === ''}
4646
/>
4747
)}
4848

4949
{authorizedOrganizationDetails.map((org) => (
5050
<RadioButton
51-
value={org.orgNumber}
51+
value={org.partyId}
5252
label={org.orgName}
5353
name='onBehalfOf'
5454
key={org.partyId}
5555
onChange={onChange}
56-
checked={onBehalfOfOrg === org.orgNumber}
56+
checked={onBehalfOf?.orgNoOrSsn === org.orgNumber}
5757
/>
5858
))}
5959
{error && (

src/layout/SigningActions/PanelAwaitingCurrentUserSignature.tsx

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import { SigningPanel } from 'src/layout/SigningActions/PanelSigning';
2020
import classes from 'src/layout/SigningActions/SigningActions.module.css';
2121
import { SubmitSigningButton } from 'src/layout/SigningActions/SubmitSigningButton';
2222
import { useItemWhenType } from 'src/utils/layout/useNodeItem';
23+
import type { OnBehalfOf } from 'src/layout/SigningActions/api';
2324

2425
type AwaitingCurrentUserSignaturePanelProps = {
2526
baseComponentId: string;
@@ -47,7 +48,7 @@ export function AwaitingCurrentUserSignaturePanel({
4748
const signingButtonText = textResourceBindings?.signingButton ?? 'signing.sign_button';
4849

4950
const [confirmReadDocuments, setConfirmReadDocuments] = useState(false);
50-
const [onBehalfOf, setOnBehalfOf] = useState<string | null>(null);
51+
const [onBehalfOf, setOnBehalfOf] = useState<OnBehalfOf | null>(null);
5152
const [onBehalfOfError, setOnBehalfOfError] = useState(false);
5253
const [confirmReadDocumentsError, setConfirmReadDocumentsError] = useState(false);
5354

@@ -95,7 +96,10 @@ export function AwaitingCurrentUserSignaturePanel({
9596
unsignedUserSigneeParties.length === 1 &&
9697
unsignedUserSigneeParties[0].partyId === unsignedAuthorizedOrgSignees.at(0)?.partyId
9798
) {
98-
setOnBehalfOf(unsignedAuthorizedOrgSignees[0].orgNumber);
99+
setOnBehalfOf({
100+
orgNoOrSsn: unsignedAuthorizedOrgSignees[0].orgNumber,
101+
partyId: unsignedAuthorizedOrgSignees[0].partyId.toString(),
102+
});
99103
}
100104
}, [unsignedUserSigneeParties, unsignedAuthorizedOrgSignees]);
101105

@@ -142,10 +146,10 @@ export function AwaitingCurrentUserSignaturePanel({
142146
<OnBehalfOfChooser
143147
currentUserSignee={unsignedUserSigneeParties.find((s) => s.partyId === currentUserPartyId)}
144148
authorizedOrganizationDetails={unsignedAuthorizedOrgSignees}
145-
onBehalfOfOrg={onBehalfOf}
149+
onBehalfOf={onBehalfOf}
146150
error={onBehalfOfError}
147151
onChange={(e) => {
148-
setOnBehalfOf(e.target.value);
152+
setOnBehalfOf(JSON.parse(e.target.value));
149153
setOnBehalfOfError(false);
150154
}}
151155
/>

src/layout/SigningActions/api.ts

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { doPerformAction } from 'src/queries/queries';
1111
import { httpGet } from 'src/utils/network/sharedNetworking';
1212
import { capitalizeName } from 'src/utils/stringHelper';
1313
import { appPath } from 'src/utils/urls/appUrlHelper';
14+
import type { SigneeState } from 'src/layout/SigneeList/api';
1415

1516
const authorizedOrganizationDetailsSchema = z.object({
1617
organizations: z.array(
@@ -81,24 +82,38 @@ export function useUserSigneeParties() {
8182
return signeeList.filter((signee) => authorizedPartyIds.includes(signee.partyId));
8283
}
8384

85+
export type OnBehalfOf = { orgNoOrSsn: string; partyId: string };
86+
8487
export function useSigningMutation() {
85-
const { instanceOwnerPartyId, instanceGuid } = useParams();
88+
const { instanceOwnerPartyId, instanceGuid, taskId } = useParams();
8689
const selectedLanguage = useCurrentLanguage();
8790
const queryClient = useQueryClient();
91+
const currentUserPartyId = useProfile()?.partyId.toString();
8892

8993
return useMutation({
90-
mutationFn: async (onBehalfOf: string | null) => {
94+
mutationFn: async (onBehalfOf: OnBehalfOf | null) => {
9195
if (instanceOwnerPartyId && instanceGuid) {
9296
return doPerformAction(
9397
instanceOwnerPartyId,
9498
instanceGuid,
95-
{ action: 'sign', ...(onBehalfOf ? { onBehalfOf } : {}) },
99+
{ action: 'sign', ...(onBehalfOf ? { onBehalfOf: onBehalfOf.orgNoOrSsn } : {}) },
96100
selectedLanguage,
97101
queryClient,
98102
);
99103
}
100104
},
101-
onSuccess: () => {
105+
onSuccess: (_data, onBehalfOf) => {
106+
// optimistically update data in cache
107+
const signeeListQueryKey = signingQueries.signeeList(instanceOwnerPartyId, instanceGuid, taskId).queryKey;
108+
queryClient.setQueryData<SigneeState[]>(signeeListQueryKey, (signeeList) => {
109+
const partyId = onBehalfOf?.partyId ?? currentUserPartyId;
110+
if (!signeeList || !partyId) {
111+
return undefined;
112+
}
113+
114+
return signeeList.map((signee) => ({ ...signee, hasSigned: signee.partyId.toString() === partyId }));
115+
});
116+
102117
// Refetch all queries related to signing to ensure we have the latest data
103118
queryClient.invalidateQueries({ queryKey: signingQueries.all });
104119
},

0 commit comments

Comments
 (0)