์คํํธ์ ํด์ฌ ํ, ๋ฐ๋ก IT ์ฐํฉ ๋์๋ฆฌ์ธ DND 8๊ธฐํ๋์ ์งํํ๋ค. DND ํ๋ก์ ํธ๋ฅผ ์งํํ๋ฉด์ ํ์ ์คํฌ๋ฆฝํธ๋ฅผ ์ฌ์ฉํ๋ ๋ชฉ์ ์ธ โ์์ ์ฑโ๊ณผ ์ด๋ฅผ ํฅ์์ํฌ ์ ์๋ ๋ฐฉ๋ฒ์ ๋ํด ๊ณ ๋ฏผํ ๋ถ๋ถ๋ค์ ๊ณต์ ํ๊ณ ์ ํ๋ค.
์๋น์ค URL -> https://www.wise24life.site
ํ์
์คํฌ๋ฆฝํธ
๋ ์๋ฐ์คํฌ๋ฆฝํธ๋ฅผ ๊ธฐ๋ฐ์ผ๋ก ์ ์ ํ์
๋ฌธ๋ฒ์ ์ถ๊ฐํ ์ธ์ด์ด๋ค. โ์ปดํ์ผโ๋จ๊ณ์์ ํ์
๊ฒ์ฌ๊ธฐ(Type Checker)๋ฅผ ํตํด ์ฌ์ ๊ฒ์ฌ๋ฅผ ํ์ฌ ๋ฐํ์์ ๋ฐ์ํ๊ฒ ๋ ์๋ฌ๋ฅผ ๋ฐฉ์งํ ์ ์๋๋ก ํ๋ค.(*๋ธ๋ผ์ฐ์ ์์๋ ์๋ฐ์คํฌ๋ฆฝํธ๋ง ๋์ํ ์ ์๊ธฐ๋๋ฌธ์ ๋น๋๊ณผ์ ์์ ํธ๋์คํ์ผ๋ฌ๋ฅผ ํตํด ์๋ฐ์คํฌ๋ฆฝํธ๋ก ๋ณํ๋๋ค. )
์ฌ์ค ๋ฐ๋ก ์ง์ ์คํํธ์ ์์ ๊ทผ๋ฌดํ ๋๋, ์น๊ฐ๋ฐ์ ๊ณต๋ถํ์ง ์ผ๋ง ์๋์ฑ๋ก ํฌ์ ๋์ด์ ํ์ ์คํฌ๋ฆฝํธ๊ฐ ์ผ๋จ ์ข๋ค๋๊น ์ฌ์ฉํ์๊ณ , ํญ์ ์๊ฐ์ ์ซ๊ฒจ ์ ๋๋ก ๊ณต๋ถํด ๋ณผ ์๊ฐ์ด ์์๋ค. ๊ทธ๋ฆฌ๊ณ DND ํ๋ก์ ํธ๋ ์ฃผ์ด์ง๋ ๊ณต์์ ์ธ ๊ฐ๋ฐ๊ธฐ๊ฐ์ด 8์ฃผ๋ฐ์ ์๋๊ธฐ์ ์ผ๋จ ๋๋๋๋ก ๊ฐ๋ฐ์ ์งํํ๋ค. ๊ทธ๋ ๊ฒ ๋์จ ์ฒด๊ณ์๋ ์ฝ๋์ด๋ค.
// types/IUser.ts
// ํธ์์ ๊ทผ๋ฌด๊ด๋ฆฌ ์๋น์ค ํน์ฑ์ด ๋ฐ์๋ ์ ์ ํ์
์ ์ธ
export type RoleType = 'WORKER' | 'MANAGER';
export interface IUser {
userName: string;
userProfileCode: number;
workPlace: string;
workLocation: string;
workTime: string;
role: RoleType;
phoneNumber: string | null; //์ ํ๋ฒํธ(๋ฏผ๊ฐํ ๊ฐ์ธ์ ๋ณด)๋ ์
๋ ฅํ์ง ์์๋ ๋๋ค.
wage: string;
email: string;
}
// ์ ์ ํ์๊ฐ์
์ ์ฌ์ฉ๋ Zustand Store ํ์ผ
// ์ ์ ๋ฑ๋ก ํผ ํ์
์ ์ธ
interface IUserForm {
role: RoleType | null;
workPlace: string | null;
workLocation: string | null;
workTime: string;
phoneNumber: string | null;
wage: string | null;
}
// ์ ์ post api ์ฐ๋
export interface MutateUserBody {
role: RoleType;
workPlace: string;
workLocation: string;
workTime: string; // "์(17:00~21:00),ํ(17:00~21:00)"
phoneNumber: string | null; // "010-0000-0000"
wage: number;
}
export const postUser = async (body: MutateUserBodyType) => {
const res = await client.post(`/api/user/signup`, { ...body });
return res;
};
ํ ๋ฒ ์ ์๋ ์ ์ ๋ ๊ธฐ๋ณธ์ ์ผ๋ก ๋ชจ๋ ํ์ด์ง์์, ๊ทธ๋ฆฌ๊ณ ๋ชจ๋ ์์ญ์์ ํ์ ์ด ์ผ์ ํ๊ฒ ์ ์ง๋์ด์ผ ์์ ์ ์ด๋ผ๊ณ ํ ์ ์๋ค. ์๋ฅผ ๋ค์ด ๋ด๊ฐ IUser์์ wage๋ฅผ string์ผ๋ก ํ์ ์ ์ ์ธํด ๋์์ผ๋ฉด ์ ์ ์ wage๋ ํญ์ stringํ์ ์ด์ด์ผ ํ๋ค. ๊ทธ๋ฐ๋ฐ ์์ฒ๋ผ ์ค๊ตฌ๋๋ฐฉ์ผ๋ก ์ฌ๋ฌํ์ผ์์ ์ ์ ์ ํ์ ์ ์ฌ์ ์ํ๋ค ๋ณด๋ฉด wage๋ฅผ number๋ก ์ ์ธํ๊ฒ ๋ ์ ์๋ค. ๋์ผํ ํ์ ์ ๋ํด์๋ ์ค๋ณต ์ ์ธ์ ํ์ง ์๊ณ , ๊ธฐ์กด์ ์ ์ํ ๊ฒ์ ์ฌํ์ฉํด์ผํ๋ค.์ด๋ฅผ ์ํด Pick๊ณผ Partial์ด๋ผ๋ ์ ํธ๋ฆฌํฐ ํ์ ์ ์ฌ์ฉํด ๋ณด์๋ค. (+Omit?) ๊ทธ๋ฆฌ๊ณ mapped type์ ํ์ฉํด ๊ธฐ์กด ์ ์๋ ํ์ ์ ์ฌํ์ฉํ๋ค.
// ์ ์ ํ์๊ฐ์
์ ์ฌ์ฉ๋ Zustand Store ํ์ผ
//BEFORE
interface IUserForm {
role: RoleType | null;
workPlace: string | null;
workLocation: string | null;
workTime: string;
phoneNumber: string | null;
wage: string | null;
}
//AFTER
type UserFormType = Partial<IUser> & { workTimeObj?: WeekWorkTimeType }; // ์
๋ ฅํ์ง ์์ ํ๋๋ undefiend ์ํ
๊ธฐ์กด์ ์ ์ ๋ฑ๋ก์ ์ํด ์ ์ํ ํ์ ์ ์๋์ ๊ฐ์ด ๊ฐ์ ๋ ์ ์๋ค.
// BEFORE
export interface MutateUserBody {
role: RoleType;
workPlace: string;
workLocation: string;
workTime: string; // "์(17:00~21:00),ํ(17:00~21:00)"
phoneNumber: string | null; // "010-0000-0000"
wage: number;
}
// AFTER
export type MutateUserBodyType = Pick<
IUser,
'role' | 'workPlace' | 'workLocation' | 'workTime' | 'phoneNumber' | 'wage'
>;
๋ง์ง๋ง์ผ๋ก ์ ์ ์ ์ ๋ณด๋ฅผ prop์ผ๋ก ๋ฃ์ด์ฃผ๋ ์ปดํฌ๋ํธ์ ๊ฒฝ์ฐ interface๋ฅผ ์๋์ ๊ฐ์ด ๊ธฐ์กด ์ ์ํ ์ ์ ์ ํ์ ์ mappingํด ์ฃผ์๋ค.
interface Props {
userProfileCode: IUser['userProfileCode'];
userName: IUser['userName'];
workTime: IUser['workTime'];
email: IUser['email'];
}
function UserProfile({ userProfileCode, userName, workTime, email }: Props) {
--- ์ดํ ์๋ต ---