-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(app-signup): add initial signup form
- Loading branch information
Showing
21 changed files
with
379 additions
and
13 deletions.
There are no files selected for viewing
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
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
32 changes: 32 additions & 0 deletions
32
packages/game-app/src/_shared/components/SelectInput/SelectInput.tsx
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,32 @@ | ||
import React from 'react'; | ||
|
||
type Option = string | { value: string; label: string }; | ||
|
||
type Props = { | ||
name: string; | ||
label: string; | ||
value: string; | ||
options: Option[]; | ||
onChange: React.ChangeEventHandler<HTMLSelectElement>; | ||
errorMessage?: string | null; | ||
}; | ||
|
||
const SelectInput: React.FC<Props> = ({ value, name, label, onChange, options, errorMessage }) => { | ||
return ( | ||
<div className="column"> | ||
<label htmlFor={name}>{label}</label> | ||
<select name={name} id={name} value={value} onChange={onChange}> | ||
{options.map(o => { | ||
const value = typeof o === 'string' ? o : o.value; | ||
const label = typeof o === 'string' ? o : o.label; | ||
return <option value={value}>{label}</option>; | ||
})} | ||
</select> | ||
{errorMessage ? <span className="error-message">{errorMessage}</span> : null} | ||
</div> | ||
); | ||
}; | ||
|
||
SelectInput.displayName = 'SelectInput'; | ||
|
||
export default SelectInput; |
3 changes: 3 additions & 0 deletions
3
packages/game-app/src/_shared/components/SelectInput/index.ts
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,3 @@ | ||
import SelectInput from './SelectInput'; | ||
|
||
export default SelectInput; |
23 changes: 23 additions & 0 deletions
23
packages/game-app/src/_shared/components/TextInput/TextInput.tsx
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,23 @@ | ||
import React from 'react'; | ||
|
||
type Props = { | ||
name: string; | ||
label: string; | ||
value: string; | ||
onChange: React.ChangeEventHandler<HTMLInputElement>; | ||
errorMessage?: string | null; | ||
}; | ||
|
||
const TextInput: React.FC<Props> = ({ name, value, errorMessage, label, onChange }) => { | ||
return ( | ||
<div className="column"> | ||
<label htmlFor={name}>{label}</label> | ||
<input type="text" value={value} name={name} id={name} onChange={onChange} /> | ||
{errorMessage ? <span className="error-message">{errorMessage}</span> : null} | ||
</div> | ||
); | ||
}; | ||
|
||
TextInput.displayName = 'TextInput'; | ||
|
||
export default TextInput; |
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,3 @@ | ||
import TextInput from './TextInput'; | ||
|
||
export default TextInput; |
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,4 @@ | ||
import SelectInput from './SelectInput'; | ||
import TextInput from './TextInput'; | ||
|
||
export { TextInput, SelectInput }; |
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
35 changes: 35 additions & 0 deletions
35
packages/game-app/src/_shared/form/FormCheckbox/FormCheckbox.tsx
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,35 @@ | ||
import React, { useCallback } from 'react'; | ||
import { Controller, ControllerRenderProps, useFormContext } from 'react-hook-form'; | ||
|
||
type Props = { | ||
name: string; | ||
label: string; | ||
}; | ||
|
||
const FormCheckbox: React.FC<Props> = ({ name, label }) => { | ||
const data = useFormContext(); | ||
|
||
const renderInput = useCallback( | ||
(props: ControllerRenderProps) => { | ||
return ( | ||
<> | ||
<input | ||
type="checkbox" | ||
id={props.name} | ||
name={props.name} | ||
checked={props.value} | ||
onChange={e => props.onChange(e.target.checked)} | ||
/> | ||
<label htmlFor={props.name}>{label}</label> | ||
</> | ||
); | ||
}, | ||
[data.errors[name], label], | ||
); | ||
|
||
return <Controller name={name} control={data.control} render={renderInput} />; | ||
}; | ||
|
||
FormCheckbox.displayName = 'FormCheckbox'; | ||
|
||
export default FormCheckbox; |
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,3 @@ | ||
import FormCheckbox from './FormCheckbox'; | ||
|
||
export default FormCheckbox; |
37 changes: 37 additions & 0 deletions
37
packages/game-app/src/_shared/form/FormSelect/FormSelect.tsx
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,37 @@ | ||
import React, { useCallback } from 'react'; | ||
import { Controller, ControllerRenderProps, useFormContext } from 'react-hook-form'; | ||
import { SelectInput } from '@pipeline/components'; | ||
|
||
type Props = {} & Omit<React.ComponentProps<typeof SelectInput>, 'errorMessage' | 'onChange' | 'value'>; | ||
|
||
const FormSelect: React.FC<Props> = ({ name, label, options }) => { | ||
const data = useFormContext(); | ||
|
||
const error = data.errors[name]; | ||
|
||
const renderInput = useCallback( | ||
(props: ControllerRenderProps) => { | ||
return ( | ||
<SelectInput | ||
name={props.name} | ||
label={label} | ||
value={props.value} | ||
options={options} | ||
onChange={props.onChange} | ||
errorMessage={error ? error.message : null} | ||
/> | ||
); | ||
}, | ||
[error, label, options], | ||
); | ||
|
||
return ( | ||
<> | ||
<Controller name={name} control={data.control} render={renderInput} /> | ||
</> | ||
); | ||
}; | ||
|
||
FormSelect.displayName = 'FormSelect'; | ||
|
||
export default FormSelect; |
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,3 @@ | ||
import FormSelect from './FormSelect'; | ||
|
||
export default FormSelect; |
39 changes: 39 additions & 0 deletions
39
packages/game-app/src/_shared/form/FormTextField/FormTextField.tsx
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,39 @@ | ||
import React, { useCallback } from 'react'; | ||
import { Controller, ControllerRenderProps, useFormContext } from 'react-hook-form'; | ||
import { TextInput } from '@pipeline/components'; | ||
|
||
type Props = { | ||
name: string; | ||
label: string; | ||
}; | ||
|
||
const FormTextField: React.FC<Props> = ({ name, label }) => { | ||
const data = useFormContext(); | ||
|
||
const error = data.errors[name]; | ||
|
||
const renderInput = useCallback( | ||
(props: ControllerRenderProps) => { | ||
return ( | ||
<TextInput | ||
name={props.name} | ||
label={label} | ||
value={props.value} | ||
onChange={props.onChange} | ||
errorMessage={error?.message} | ||
/> | ||
); | ||
}, | ||
[error, label], | ||
); | ||
|
||
return ( | ||
<> | ||
<Controller name={name} control={data.control} render={renderInput} /> | ||
</> | ||
); | ||
}; | ||
|
||
FormTextField.displayName = 'FormTextField'; | ||
|
||
export default FormTextField; |
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,3 @@ | ||
import FormTextField from './FormTextField'; | ||
|
||
export default FormTextField; |
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,5 @@ | ||
import FormTextField from './FormTextField'; | ||
import FormCheckbox from './FormCheckbox'; | ||
import FormSelect from './FormSelect'; | ||
|
||
export { FormTextField, FormCheckbox, FormSelect }; |
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
Oops, something went wrong.