Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions src/app/(user)/edit/_components/form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { ErrorMsg, ErrorMsgFloat } from '../../register/_components/errorMsg';
import Image from 'next/image';

import { zodResolver } from '@hookform/resolvers/zod';
import { sizeJersey } from '@/const/size';
import { SizeJersey, sizeJersey } from '@/const/size';
import { faculties } from '@/const/faculties';
import { EditForm, EditSchema } from '@/schema/edit';
import { educationsMap, educationsMapReverse } from '@/const/educations';
Expand Down Expand Up @@ -149,10 +149,7 @@ export default function Form() {
<DropdownInput
value={educationsMap[user.education]}
setValue={val =>
setValue(
'education',
educationsMapReverse[val as 'กำลังศึกษา' | 'จบการศึกษา'],
)
val && setValue('education', educationsMapReverse[val])
}
placeholder="กำลังศึกษาอยู่"
choices={Object.keys(educationsMapReverse).map(key => key)}
Expand Down Expand Up @@ -235,7 +232,9 @@ export default function Form() {
<Label isRequired>ขนาดเสื้อ</Label>
<DropdownInput
value={user.sizeJersey}
setValue={updateField('sizeJersey')}
setValue={(val: string) =>
val && setValue('sizeJersey', val as SizeJersey)
}
placeholder="กรุณาเลือก"
choices={[...sizeJersey]}
/>
Expand Down
19 changes: 18 additions & 1 deletion src/app/(user)/register/_components/subpages/two.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import { universities } from '@/const/universities';
import { faculties } from '@/const/faculties';
import { sizeJersey } from '@/const/size';
import { statusMap } from '@/const/status';
// import Consent from '../policy/consent';

interface TwoProps {
setStep: (value: number) => void;
Expand Down Expand Up @@ -73,6 +74,15 @@ export default function Two({ setStep, form }: TwoProps) {
useEffect(() => {
let status: RegisterForm['status'];

// not specified
if (user.education == 'notSpecified') {
setValue('graduatedYear', '9999');
setValue('faculty', 'ไม่ระบุ');
setValue('status', 'general_public');
setValue('university', 'ไม่ประสงค์เเจ้ง');
return;
}

// set default value
if (
!!user.education &&
Expand Down Expand Up @@ -152,7 +162,7 @@ export default function Two({ setStep, form }: TwoProps) {
</div>

{/* university */}
{user.education && (
{user.education && user.education != 'notSpecified' && (
<div className="relative space-y-1">
<Label isRequired>
{user.education == 'studying'
Expand Down Expand Up @@ -245,6 +255,13 @@ export default function Two({ setStep, form }: TwoProps) {
<div className="relative space-y-1">
<Label>โรคประจำตัว</Label>
<TextInput {...register('chronicDisease')} />
{/* <div className='pt-0.5'></div>
<Consent
value={true}
setValue={(val: boolean) => {}}
label="คุณกลัวความสูงหรือไม่"
isRequired={false}
/> */}
<ErrorMsgFloat>{errors.chronicDisease?.message}</ErrorMsgFloat>
</div>

Expand Down
4 changes: 3 additions & 1 deletion src/const/educations.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
export const educations = ['studying', 'graduated'] as const;
export const educations = ['studying', 'graduated', 'notSpecified'] as const;
export type Education = (typeof educations)[number];

export const educationsMap = {
studying: 'กำลังศึกษา',
graduated: 'จบการศึกษา',
notSpecified: 'ไม่ประสงค์เเจ้ง',
};

export const educationsMapReverse: { [key: string]: Education } = {
กำลังศึกษา: 'studying',
จบการศึกษา: 'graduated',
ไม่ประสงค์เเจ้ง: 'notSpecified',
};
1 change: 1 addition & 0 deletions src/const/universities.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export const universities = [
'ไม่ประสงค์เเจ้ง',
'จุฬาลงกรณ์มหาวิทยาลัย',
'มหาวิทยาลัยเกษตรศาสตร์',
'มหาวิทยาลัยเกษตรศาสตร์ วิทยาเขตกำแพงแสน',
Expand Down
2 changes: 1 addition & 1 deletion src/schema/edit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { faculties } from '@/const/faculties';
export const EditSchema = z.object({
name: z.string().min(1, 'กรุณากรอกชื่อ-นามสกุล'),
email: z.string().email('กรุณากรอกอีเมล'),
phone: z.string().regex(/^\d+$/, 'กรุณากรอกเลข 0-9 เท่านั้น'),
phone: z.string().regex(/^\d.{10}$/, 'กรุณากรอกเลขเบอร์ 10 หลัก'),
age: z
.string({
message: 'กรุณากรอกอายุ',
Expand Down
2 changes: 1 addition & 1 deletion src/schema/register.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { faculties } from '@/const/faculties';
export const RegisterSchema = z.object({
name: z.string().min(1, 'กรุณากรอกชื่อ-นามสกุล'),
email: z.string().email('กรุณากรอกอีเมล'),
phone: z.string().regex(/^\d+$/, 'กรุณากรอกเลข 0-9 เท่านั้น'),
phone: z.string().regex(/^\d.{10}$/, 'กรุณากรอกเลขเบอร์ 10 หลัก'),
age: z
.string({
message: 'กรุณากรอกอายุ',
Expand Down