-
Notifications
You must be signed in to change notification settings - Fork 1
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
21 changed files
with
1,060 additions
and
40 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
'use server'; | ||
|
||
import { FormState } from '@/app/ui/view/molecule/form/form-root'; | ||
import { z } from 'zod'; | ||
|
||
// message name은 logic 구현할 때 통일할 예정 | ||
const SignUpFormSchema = z | ||
.object({ | ||
userId: z | ||
.string() | ||
.min(6, { | ||
message: 'User ID must be at least 6 characters', | ||
}) | ||
.max(20, { | ||
message: 'User ID must be at most 20 characters', | ||
}), | ||
password: z.string().regex(/^(?=.*[A-Za-z])(?=.*\d)(?=.*[@$!^%*#?&])[A-Za-z\d@$!^%*#?&]{8,}$/, { | ||
message: 'Password must contain at least 8 characters, one letter, one number and one special character', | ||
}), | ||
confirmPassword: z.string(), | ||
studentNumber: z.string().length(8, { message: '학번은 8자리 입니다' }).startsWith('60', { | ||
message: '학번은 60으로 시작합니다', | ||
}), | ||
english: z.enum(['basic', 'level12', 'level34', 'bypass']), | ||
}) | ||
.superRefine(({ confirmPassword, password }, ctx) => { | ||
console.log('refind', confirmPassword, password); | ||
if (confirmPassword !== password) { | ||
ctx.addIssue({ | ||
code: 'custom', | ||
message: 'The passwords did not match', | ||
path: ['confirmPassword'], | ||
}); | ||
} | ||
}); | ||
|
||
type User = z.infer<typeof SignUpFormSchema>; | ||
|
||
export async function createUser(prevState: FormState, formData: FormData): Promise<FormState> { | ||
const validatedFields = SignUpFormSchema.safeParse({ | ||
userId: formData.get('userId'), | ||
password: formData.get('password'), | ||
confirmPassword: formData.get('confirmPassword'), | ||
studentNumber: formData.get('studentNumber'), | ||
english: formData.get('english'), | ||
}); | ||
|
||
if (!validatedFields.success) { | ||
return { | ||
errors: validatedFields.error.flatten().fieldErrors, | ||
message: 'error', | ||
}; | ||
} | ||
|
||
// Call the API to create a user | ||
// but now mock the response | ||
await new Promise((resolve) => { | ||
setTimeout(() => { | ||
resolve(''); | ||
}, 3000); | ||
}); | ||
|
||
return { | ||
errors: {}, | ||
message: 'blacnk', | ||
}; | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import React from 'react'; | ||
|
||
const LoadingSpinner = ({ ...props }) => ( | ||
<svg {...props} xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor"> | ||
<path fill="none" d="M0 0h24v24H0z" /> | ||
<path d="M18.364 5.636L16.95 7.05A7 7 0 1 0 19 12h2a9 9 0 1 1-2.636-6.364z" /> | ||
</svg> | ||
); | ||
|
||
export default LoadingSpinner; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import TextInput from '../../atom/text-input/text-input'; | ||
import { FormContext } from './form.context'; | ||
import { useContext } from 'react'; | ||
import { useFormStatus } from 'react-dom'; | ||
|
||
interface FormNumberInputProps { | ||
label: string; | ||
id: string; | ||
placeholder: string; | ||
required?: boolean; | ||
} | ||
|
||
export function FormNumberInput({ label, id, placeholder, required = false }: FormNumberInputProps) { | ||
const { errors } = useContext(FormContext); | ||
const { pending } = useFormStatus(); | ||
|
||
return ( | ||
<div className="group"> | ||
<label | ||
htmlFor={id} | ||
className="mb-2 block text-sm font-medium group-has-[:required]:after:pl-1 group-has-[:required]:after:content-['*'] group-has-[:required]:after:text-red-400" | ||
> | ||
{label} | ||
</label> | ||
<TextInput | ||
required={required} | ||
disabled={pending} | ||
error={errors[id] ? true : false} | ||
errorMessages={errors[id]} | ||
type={'number'} | ||
id={id} | ||
name={id} | ||
placeholder={placeholder} | ||
/> | ||
</div> | ||
); | ||
} |
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 TextInput from '../../atom/text-input/text-input'; | ||
import { FormContext } from './form.context'; | ||
import { useContext } from 'react'; | ||
import { useFormStatus } from 'react-dom'; | ||
|
||
interface FormPasswordInputProps { | ||
label: string; | ||
id: string; | ||
placeholder: string; | ||
required?: boolean; | ||
} | ||
|
||
export function FormPasswordInput({ label, id, placeholder, required = false }: FormPasswordInputProps) { | ||
const { errors } = useContext(FormContext); | ||
const { pending } = useFormStatus(); | ||
|
||
return ( | ||
<div className="group"> | ||
<label | ||
htmlFor={id} | ||
className="mb-2 block text-sm font-medium group-has-[:required]:after:pl-1 group-has-[:required]:after:content-['*'] group-has-[:required]:after:text-red-400" | ||
> | ||
{label} | ||
</label> | ||
<TextInput | ||
required={required} | ||
disabled={pending} | ||
error={errors[id] ? true : false} | ||
errorMessages={errors[id]} | ||
type={'password'} | ||
id={id} | ||
name={id} | ||
placeholder={placeholder} | ||
/> | ||
</div> | ||
); | ||
} |
Oops, something went wrong.