This repository was archived by the owner on Jun 13, 2025. It is now read-only.
-
Couldn't load subscription status.
- Fork 2
feat: form improvement #153
Merged
Merged
Changes from 3 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
15b6d2f
fix: halal
gxjakkap fa9e162
fix: hide up-down button in number input
gxjakkap 43f0b62
feat: add dynamic select
gxjakkap 439750a
fix: add logo.png back
gxjakkap 0186be5
refactor: move default value for dynamic select to page.tsx
gxjakkap 8519f65
fix: improve form validation
gxjakkap 8f07c2c
fix: remove ปวช.3 from grad value list
gxjakkap 93f2a3c
fix: typo in form navbar
gxjakkap File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Binary file not shown.
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -112,4 +112,9 @@ | |
| -webkit-appearance: none; | ||
| margin: 0; | ||
| } | ||
| input[type=number] { | ||
| -moz-appearance:textfield; | ||
| } | ||
| } | ||
|
|
||
|
|
||
This file contains hidden or 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 hidden or 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,38 @@ | ||
| import { SelectProps } from "."; | ||
| import DynamicSelect from "./dynamic-select"; | ||
|
|
||
| function BloodGroupSelector({ | ||
| onValueChange = () => {}, | ||
| ...props | ||
| }: SelectProps) { | ||
| const preset = [ | ||
| { | ||
| value: "A", | ||
| label: "A", | ||
| }, | ||
| { | ||
| value: "B", | ||
| label: "B", | ||
| }, | ||
| { | ||
| value: "O", | ||
| label: "O", | ||
| }, | ||
| { | ||
| value: "AB", | ||
| label: "AB", | ||
| }, | ||
| ]; | ||
|
|
||
| return ( | ||
| <DynamicSelect | ||
| {...props} | ||
| onValueChange={onValueChange} | ||
| preset={preset} | ||
| formLabel="กรุ๊ปเลือด" | ||
| placeholder="ระบุกรุ๊ปเลือดอื่น ๆ" | ||
| /> | ||
| ); | ||
| } | ||
|
|
||
| export default BloodGroupSelector; |
This file contains hidden or 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,79 @@ | ||
| import { useEffect, useState } from "react"; | ||
| import CustomSelect, { SelectProps } from "."; | ||
| import { FormControl, FormItem, FormLabel, FormMessage } from "../ui/form"; | ||
| import { Input } from "../ui/input"; | ||
|
|
||
| interface PresetEa { | ||
| value: string; | ||
| label: string; | ||
| } | ||
|
|
||
| interface DynamicSelectProps extends Omit<SelectProps, "onValueChange"> { | ||
| onValueChange: (data: string) => void; | ||
| preset: PresetEa[]; | ||
| formLabel: string; | ||
| } | ||
|
|
||
| export default function DynamicSelect(props: DynamicSelectProps) { | ||
| const preset = props.preset; | ||
| const options = [...preset, { value: "Other", label: "อื่น ๆ" }]; | ||
|
|
||
| const [selected, setSelected] = useState(() => { | ||
| return preset.some((item) => item.value === props.value) | ||
| ? props.value | ||
| : "Other"; | ||
| }); | ||
|
|
||
| useEffect(() => { | ||
| const newSelected = preset.some((item) => item.value === props.value) | ||
| ? props.value | ||
| : "Other"; | ||
| setSelected(newSelected); | ||
| }, [props.value, preset]); | ||
|
|
||
| const handleSelectChange = (value: string) => { | ||
| setSelected(value); | ||
| if (value === "Other") { | ||
| props.onValueChange(""); | ||
| } else { | ||
| props.onValueChange(value); | ||
| } | ||
| }; | ||
|
|
||
| return ( | ||
| <div className="flex gap-x-2"> | ||
| <div className="flex-1"> | ||
| <FormItem> | ||
| <FormLabel>{props.formLabel}</FormLabel> | ||
| <FormControl> | ||
| <CustomSelect | ||
| value={selected} | ||
| onValueChange={handleSelectChange} | ||
| options={options} | ||
| disabled={props.disabled} | ||
| /> | ||
| </FormControl> | ||
| <FormMessage /> | ||
| </FormItem> | ||
| </div> | ||
| {selected === "Other" && ( | ||
| <div className="flex-1"> | ||
| <FormItem> | ||
| <FormLabel>{props.placeholder}</FormLabel> | ||
| <FormControl> | ||
| <Input | ||
| placeholder={props.placeholder} | ||
| value={props.value} | ||
| onChange={(e) => { | ||
| e.preventDefault(); | ||
| props.onValueChange(e.target.value); | ||
| }} | ||
| disabled={props.disabled} | ||
| /> | ||
| </FormControl> | ||
| </FormItem> | ||
| </div> | ||
| )} | ||
| </div> | ||
| ); | ||
| } |
This file contains hidden or 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,42 @@ | ||
| import { SelectProps } from "."; | ||
| import DynamicSelect from "./dynamic-select"; | ||
|
|
||
| function GraduationSelector({ | ||
| onValueChange = () => {}, | ||
| ...props | ||
| }: SelectProps) { | ||
| const preset = [ | ||
| { | ||
| value: "มัธยมศึกษาปีที่ 4", | ||
| label: "มัธยมศึกษาปีที่ 4", | ||
| }, | ||
| { | ||
| value: "มัธยมศึกษาปีที่ 5", | ||
| label: "มัธยมศึกษาปีที่ 5", | ||
| }, | ||
| { | ||
| value: "ปวช. 1", | ||
| label: "ปวช. 1", | ||
| }, | ||
| { | ||
| value: "ปวช. 2", | ||
| label: "ปวช. 2", | ||
| }, | ||
| { | ||
| value: "ปวช. 3", | ||
| label: "ปวช. 3", | ||
| }, | ||
| ]; | ||
|
|
||
| return ( | ||
| <DynamicSelect | ||
| {...props} | ||
| onValueChange={onValueChange} | ||
| preset={preset} | ||
| formLabel="ระดับชั้นการศึกษา" | ||
| placeholder="ระบุระดับชั้นการศึกษาอื่น ๆ" | ||
| /> | ||
| ); | ||
| } | ||
|
|
||
| export default GraduationSelector; |
30 changes: 30 additions & 0 deletions
30
apps/web/src/components/select/parentrelation-dynselect.tsx
This file contains hidden or 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,30 @@ | ||
| import { SelectProps } from "."; | ||
| import DynamicSelect from "./dynamic-select"; | ||
|
|
||
| function ParentRelationSelector({ | ||
| onValueChange = () => {}, | ||
| ...props | ||
| }: SelectProps) { | ||
| const preset = [ | ||
| { | ||
| value: "บิดา", | ||
| label: "บิดา", | ||
| }, | ||
| { | ||
| value: "มารดา", | ||
| label: "มารดา", | ||
| }, | ||
| ]; | ||
|
|
||
| return ( | ||
| <DynamicSelect | ||
| {...props} | ||
| onValueChange={onValueChange} | ||
| preset={preset} | ||
| formLabel="ความสัมพันธ์กับผู้ปกครอง" | ||
| placeholder="ระบุความสัมพันธ์" | ||
| /> | ||
| ); | ||
| } | ||
|
|
||
| export default ParentRelationSelector; |
This file contains hidden or 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,34 @@ | ||
| import { SelectProps } from "."; | ||
| import DynamicSelect from "./dynamic-select"; | ||
|
|
||
| function PreferFoodSelector({ | ||
| onValueChange = () => {}, | ||
| ...props | ||
| }: SelectProps) { | ||
| const preset = [ | ||
| { | ||
| value: "ปกติ", | ||
| label: "ปกติ", | ||
| }, | ||
| { | ||
| value: "ฮาลาล", | ||
| label: "ฮาลาล", | ||
| }, | ||
| { | ||
| value: "มังสวิรัติ", | ||
| label: "มังสวิรัติ", | ||
| }, | ||
| ]; | ||
|
|
||
| return ( | ||
| <DynamicSelect | ||
| {...props} | ||
| onValueChange={onValueChange} | ||
| preset={preset} | ||
| formLabel="อาหารที่รับประทาน" | ||
| placeholder="ระบุอาหารอื่น ๆ" | ||
| /> | ||
| ); | ||
| } | ||
|
|
||
| export default PreferFoodSelector; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.