useProjectForm
The useProjectForm hook is a custom hook used to handle the logic ( input, validation, etc ) behind the form regarding project data.
Components
Form Initialization
The hook uses the useForm
hook from Mantine to initialize the form with either the provided initialValues
or default values. It also sets up form validation using Zod.
Mutation Hooks
The hook uses the useAddProjectMutation and useUpdateProjectMutation hooks to handle adding and updating projects.
Image Handling Functions
The hook provides several functions to handle image selection:
handleCustomImage
: Sets the form'simage
value to a selected file and setsuseDefaultImage
to false.handleDefaultImage
: Sets the form'simage
value to a selected URL.handleClearImage
: Resets the form'simage
value to the default image and setsuseDefaultImage
to true.
Form Submission
The handleSubmit
function validates the form, constructs a project object from the form values, and triggers either an add or update mutation depending on whether an id is present in the form values.
Behavior
This hook returns the form values and its handling functions, image handling functions and submission function