-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
117 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { Field, FormRenderProps, useForm, useFormState } from 'react-final-form'; | ||
|
||
export default function Form({ handleSubmit }: { handleSubmit: FormRenderProps['handleSubmit'] }) { | ||
const form = useForm(); | ||
const { submitting, pristine } = useFormState(); | ||
|
||
return ( | ||
<form id="exampleForm" onSubmit={handleSubmit}> | ||
<div> | ||
<label>First Name</label> | ||
<Field name="firstName" component="input" type="text" placeholder="First Name" /> | ||
</div> | ||
<div> | ||
<label>Last Name</label> | ||
<Field name="lastName" component="input" type="text" placeholder="Last Name" /> | ||
</div> | ||
<div> | ||
<label>Favorite Color</label> | ||
<Field name="favoriteColor" component="select"> | ||
<option /> | ||
<option value="#ff0000">️ Red</option> | ||
<option value="#00ff00">Green</option> | ||
<option value="#0000ff">Blue</option> | ||
</Field> | ||
</div> | ||
<div className="buttons"> | ||
<button type="submit" disabled={submitting || pristine}> | ||
Submit | ||
</button> | ||
<button type="button" onClick={form.reset} disabled={submitting || pristine}> | ||
Reset | ||
</button> | ||
</div> | ||
</form> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { z } from 'zod'; | ||
|
||
const ZodProjectSchema = z.object({ | ||
firstName: z.string().nonempty(), | ||
lastName: z.string().nonempty(), | ||
favoriteColor: z.string().optional(), | ||
}); | ||
|
||
export type ProjectSchema = z.infer<typeof ZodProjectSchema>; | ||
|
||
export const validator = (formValues: ProjectSchema) => { | ||
const validation = ZodProjectSchema.safeParse(formValues); | ||
if (validation.success) { | ||
return {}; | ||
} | ||
return validation.error; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { Form, FormProps } from 'react-final-form'; | ||
|
||
import { ProjectSchema, validator } from './validations'; | ||
|
||
export default function FormWrapper(formProps: FormProps<ProjectSchema>) { | ||
return <Form<ProjectSchema> validate={validator} {...formProps} />; | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { useForm, useFormState } from 'react-final-form'; | ||
|
||
import { Button } from 'components/button/component'; | ||
|
||
export default function NewProjectHeader() { | ||
const { invalid } = useFormState(); | ||
const { submit } = useForm(); | ||
|
||
return ( | ||
<header className="flex justify-between items-center"> | ||
<h2 className="text-3xl font-display">New project</h2> | ||
<Button type="submit" theme="green" disabled={invalid} onClick={submit}> | ||
Save changes | ||
</Button> | ||
</header> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,33 @@ | ||
import Wrapper from 'containers/wrapper'; | ||
|
||
import { FORM_STEPS } from '../constants'; | ||
import MyProjectsHeader from '../header'; | ||
import Form from '../form'; | ||
import FormWrapper from '../form/wrapper'; | ||
import MyProjectsSidebar from '../sidebar'; | ||
|
||
import NewProjectHeader from './header'; | ||
|
||
export default function NewProject() { | ||
return ( | ||
<Wrapper> | ||
<MyProjectsHeader /> | ||
<div className="grid grid-cols-12 gap-16"> | ||
<div className="col-span-3"> | ||
<MyProjectsSidebar sections={FORM_STEPS} /> | ||
</div> | ||
<div className="col-span-9">WIP Form</div> | ||
</div> | ||
<Wrapper className="w-full"> | ||
<FormWrapper | ||
onSubmit={async (data) => console.log('form wrapper', data)} | ||
render={({ handleSubmit }) => { | ||
return ( | ||
<div className="flex flex-col gap-14"> | ||
<NewProjectHeader /> | ||
<div className="grid grid-cols-12 gap-16"> | ||
<div className="col-span-3"> | ||
<MyProjectsSidebar sections={FORM_STEPS} /> | ||
</div> | ||
<div className="col-span-9"> | ||
<Form handleSubmit={handleSubmit} /> | ||
</div> | ||
</div> | ||
</div> | ||
); | ||
}} | ||
/> | ||
</Wrapper> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters