I'll explain more what I'm actually trying to do:
The server is expecting this type from the client:
export type FormInputV1 = {
congestion?: InputMaybe<CongestionInputV1>;
disciplineAndMaxDepth?: InputMaybe<DisciplineAndMaxDepthInputV1>;
maxDepth?: InputMaybe<MaxDepthInputV1>;
reportName?: InputMaybe<ReportNameInputV1>;
visibility?: InputMaybe<VisibilityInputV1>;
weather?: InputMaybe<WeatherInputV1>;
wildlife?: InputMaybe<WildlifeInputV1>;
};
Regarding UX: the goal is that rather than having to sift through all the optional fields every time the user goes to log their dive (because there will be many more optional fields), they are able to choose which fields they want to appear in their own form. And then they reuse that form.
So, the client returns a concrete version of this type, with the fields they want.
That's the form builder.
Now they have a concrete type in the database, that they use to build reports on, i.e. fill out the form they created.
The form builder looks like this right now:
export function FormBuilder() {
let navigation = useNavigation<AllNavigationProps>();
const { putFormMutation, result } = useInsertForm();
type ImportValues = Record<
keyof FormInputV1,
{ active: boolean; fieldOrder: number }
>;
let allFields = FormV1Wrapper.getKeyArray();
type LocalValues = { name: string };
type FormValues = ImportValues & LocalValues;
const {
control,
handleSubmit,
formState: { errors },
} = useForm<FormValues>({});
const onSubmit: SubmitHandler<FormValues> = (formData) => {
let newForm = FormV1Wrapper.createForm(formData);
const formInput: FormInput = {
v1: newForm,
};
// TODO: Add originalform and previousform for "editing"?
const formDetailsInput: FormDetailsInput = {
formName: "memes",
// originalFormId: _,
// previousFormId: _
};
putFormMutation({ variables: { formDetailsInput, formInput } });
};
...
}