Skip to content

Commit

Permalink
Fix prefill validation issue
Browse files Browse the repository at this point in the history
  • Loading branch information
hariombalhara committed May 9, 2023
1 parent 21319da commit 45fb94c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ function SelectWidget({ listValues, setValue, value, ...remainingProps }: Select
value: item.value,
};
});
const defaultValue = selectItems.find((item) => item.value === value);
const validValue = selectItems.find((item) => item.value === value);

return (
<Select
Expand All @@ -196,7 +196,7 @@ function SelectWidget({ listValues, setValue, value, ...remainingProps }: Select
setValue(item.value);
}}
isDisabled={remainingProps.readOnly}
defaultValue={defaultValue}
value={validValue}
options={selectItems}
{...remainingProps}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,8 @@ function RoutingForm({ form, profile, ...restProps }: Props) {
// - like a network error
// - or he abandoned booking flow in between
const formFillerId = formFillerIdRef.current;
const decidedActionRef = useRef<{ action: Route["action"]; response: Response }>();
const decidedActionWithResponseRef = useRef<{ action: Route["action"]; response: Response }>();
const router = useRouter();

const onSubmit = (response: Response) => {
const decidedAction = processRoute({ form, response });

Expand All @@ -67,7 +66,7 @@ function RoutingForm({ form, profile, ...restProps }: Props) {
formFillerId,
response: response,
});
decidedActionRef.current = {
decidedActionWithResponseRef.current = {
action: decidedAction,
response,
};
Expand All @@ -80,15 +79,15 @@ function RoutingForm({ form, profile, ...restProps }: Props) {

const responseMutation = trpc.viewer.appRoutingForms.public.response.useMutation({
onSuccess: () => {
const decidedActionWithResponse = decidedActionRef.current;
const decidedActionWithResponse = decidedActionWithResponseRef.current;
if (!decidedActionWithResponse) {
return;
}
const fields = form.fields;
if (!fields) {
throw new Error("Routing Form fields must exist here");
}
const allURLSearchParams = getAllUrlSearchParams(decidedActionWithResponse.response, fields);
const allURLSearchParams = getUrlSearchParamsToForward(decidedActionWithResponse.response, fields);
const decidedAction = decidedActionWithResponse.action;

//TODO: Maybe take action after successful mutation
Expand Down Expand Up @@ -179,7 +178,7 @@ function RoutingForm({ form, profile, ...restProps }: Props) {
);
}

function getAllUrlSearchParams(response: Response, fields: NonNullable<Props["form"]["fields"]>) {
function getUrlSearchParamsToForward(response: Response, fields: NonNullable<Props["form"]["fields"]>) {
const paramsFromResponse: Record<string, string | string[]> = {};
const paramsFromCurrentUrl: Record<string, string | string[]> = {};

Expand Down

0 comments on commit 45fb94c

Please sign in to comment.