Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Patient Registration Form: Move restore draft button beside generate/link abha number #8741

Merged
merged 4 commits into from
Oct 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 37 additions & 41 deletions src/Components/Form/Form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ type Props<T extends FormDetails> = {
className?: string;
defaults: T;
asyncGetDefaults?: (() => Promise<T>) | false;
onlyChild?: boolean;
validate?: (form: T) => FormErrors<T>;
onSubmit: (form: T) => Promise<FormErrors<T> | void>;
onCancel?: () => void;
Expand All @@ -23,6 +22,7 @@ type Props<T extends FormDetails> = {
cancelLabel?: string;
onDraftRestore?: (newState: FormState<T>) => void;
children: (props: FormContextValue<T>) => React.ReactNode;
hideRestoreDraft?: boolean;
};

const Form = <T extends FormDetails>({
Expand Down Expand Up @@ -87,47 +87,43 @@ const Form = <T extends FormDetails>({
props.onDraftRestore?.(newState);
}}
formData={state.form}
/>
<Provider
value={(name: keyof T, validate?: FieldValidator<T[keyof T]>) => {
return {
name,
id: name,
onChange: ({ name, value }: FieldChangeEvent<T[keyof T]>) =>
dispatch({
type: "set_field",
name,
value,
error: validate?.(value),
}),
value: state.form[name],
error: state.errors[name],
disabled,
};
}}
hidden={props.hideRestoreDraft}
>
{props.onlyChild ? (
<Consumer>{props.children}</Consumer>
) : (
<>
<div className="my-6">
<Consumer>{props.children}</Consumer>
</div>
<div className="flex flex-col-reverse justify-end gap-3 sm:flex-row">
<Cancel
onClick={props.onCancel}
label={props.cancelLabel ?? "Cancel"}
/>
<Submit
data-testid="submit-button"
type="submit"
disabled={disabled}
label={props.submitLabel ?? "Submit"}
/>
</div>
</>
)}
</Provider>
<Provider
value={(name: keyof T, validate?: FieldValidator<T[keyof T]>) => {
return {
name,
id: name,
onChange: ({ name, value }: FieldChangeEvent<T[keyof T]>) =>
dispatch({
type: "set_field",
name,
value,
error: validate?.(value),
}),
value: state.form[name],
error: state.errors[name],
disabled,
};
}}
>
<div className="my-6">
<Consumer>{props.children}</Consumer>
</div>
<div className="flex flex-col-reverse justify-end gap-3 sm:flex-row">
<Cancel
onClick={props.onCancel}
label={props.cancelLabel ?? "Cancel"}
/>
<Submit
data-testid="submit-button"
type="submit"
disabled={disabled}
label={props.submitLabel ?? "Submit"}
/>
</div>
</Provider>
</DraftSection>
</form>
);
};
Expand Down
Loading
Loading