diff --git a/assets/images/add.svg b/assets/images/add.svg new file mode 100644 index 0000000..b8e4137 --- /dev/null +++ b/assets/images/add.svg @@ -0,0 +1,5 @@ + + + + + diff --git a/assets/images/arrow_back.svg b/assets/images/arrow_back.svg new file mode 100644 index 0000000..d183be3 --- /dev/null +++ b/assets/images/arrow_back.svg @@ -0,0 +1,5 @@ + + + + + diff --git a/src/app/tutoring/invite.tsx b/src/app/tutoring/invite.tsx new file mode 100644 index 0000000..6716815 --- /dev/null +++ b/src/app/tutoring/invite.tsx @@ -0,0 +1,5 @@ +import { InviteScreen } from '@/features/tutoring/InviteScreen'; + +export default function Screen() { + return ; +} diff --git a/src/app/tutoring/student.tsx b/src/app/tutoring/student.tsx new file mode 100644 index 0000000..df84984 --- /dev/null +++ b/src/app/tutoring/student.tsx @@ -0,0 +1,6 @@ +import { StudentInfoScreen } from '@/features/tutoring/StudentInfoScreen'; + +// TODO: 앞 단계가 생기면 실제로 불러온 출처를 넘깁니다. +export default function Screen() { + return ; +} diff --git a/src/app/tutoring/textbook.tsx b/src/app/tutoring/textbook.tsx new file mode 100644 index 0000000..977912c --- /dev/null +++ b/src/app/tutoring/textbook.tsx @@ -0,0 +1,8 @@ +import { useLocalSearchParams } from 'expo-router'; +import { TextbookScreen } from '@/features/tutoring/TextbookScreen'; +import { isPrefillSource } from '@/features/tutoring/TutoringFormLayout'; + +export default function Screen() { + const { source } = useLocalSearchParams<{ source?: string }>(); + return ; +} diff --git a/src/components/Chip.tsx b/src/components/Chip.tsx index f395787..5f53128 100644 --- a/src/components/Chip.tsx +++ b/src/components/Chip.tsx @@ -8,6 +8,7 @@ const colors = { background: semantic.surface.default, border: semantic.border.default, text: semantic.text.default.normal, + mutedText: semantic.text.default.weak, selectedBackground: semantic.action.default, selectedBorder: semantic.border.focused, selectedText: semantic.text.default.inverse, @@ -16,14 +17,16 @@ const colors = { export type ChipProps = Omit & { label: string; selected?: boolean; + /** true면 선택되지 않았을 때 글자를 연한 색(text/default/weak)으로 보여 줍니다. */ + muted?: boolean; }; /** 둥근 선택 칩. 너비는 글자 길이에 맞춰집니다. */ -export function Chip({ label, selected = false, ...props }: ChipProps) { +export function Chip({ label, selected = false, muted = false, ...props }: ChipProps) { return ( - + {label} diff --git a/src/components/ProgressBar.tsx b/src/components/ProgressBar.tsx index ccf0b78..74dc5c7 100644 --- a/src/components/ProgressBar.tsx +++ b/src/components/ProgressBar.tsx @@ -1,6 +1,6 @@ import { StyleSheet, Text, View } from 'react-native'; import { semantic } from '@/styles/colors'; -import { gap, radius } from '@/styles/measurement'; +import { gap, padding, radius } from '@/styles/measurement'; import { fontSize, fontWeight, letterSpacing, lineHeight } from '@/styles/typography'; const SEGMENT_WIDTH = 54; @@ -13,9 +13,11 @@ export type ProgressBarProps = { total: number; /** 막대 아래 `step/total` 표시 여부 */ showLabel?: boolean; + /** true면 막대가 부모 너비를 꽉 채우고 칸 너비를 나눠 가집니다. */ + stretch?: boolean; }; -export function ProgressBar({ step, total, showLabel = true }: ProgressBarProps) { +export function ProgressBar({ step, total, showLabel = true, stretch = false }: ProgressBarProps) { const current = Math.min(Math.max(step, 0), total); return ( @@ -25,11 +27,14 @@ export function ProgressBar({ step, total, showLabel = true }: ProgressBarProps) aria-valuemax={total} aria-valuenow={current} aria-valuetext={`${current}/${total}`} - style={s.root} + style={[s.root, stretch && s.rootStretch]} > - + {Array.from({ length: total }, (_, i) => ( - + ))} {showLabel ? ( @@ -43,13 +48,16 @@ export function ProgressBar({ step, total, showLabel = true }: ProgressBarProps) const s = StyleSheet.create({ root: { alignItems: 'center', gap: gap[12] }, + rootStretch: { alignSelf: 'stretch', paddingVertical: padding[4] }, track: { flexDirection: 'row', gap: gap[2] }, + trackStretch: { alignSelf: 'stretch', paddingHorizontal: padding[4] }, segment: { width: SEGMENT_WIDTH, height: SEGMENT_HEIGHT, borderRadius: radius.small, backgroundColor: semantic.surface.disabled, }, + segmentStretch: { flex: 1, width: undefined }, segmentFilled: { backgroundColor: semantic.icon.brand }, label: { fontSize: fontSize[12], diff --git a/src/features/tutoring/FormFields.tsx b/src/features/tutoring/FormFields.tsx new file mode 100644 index 0000000..d25feaa --- /dev/null +++ b/src/features/tutoring/FormFields.tsx @@ -0,0 +1,115 @@ +import { StyleSheet, Text, View } from 'react-native'; +import { Chip } from '@/components/Chip'; +import { TextInput } from '@/components/TextInput'; +import type { TextInputProps } from '@/components/TextInput'; +import { semantic } from '@/styles/colors'; +import { gap, padding, unit } from '@/styles/measurement'; +import { typography } from '@/styles/typography'; + +export const TOO_LONG_MESSAGE = '글자 수가 초과되었어요'; + +/** 앞뒤 공백을 뺀 글자 수가 max를 넘는지 봅니다. 넘어도 입력은 막지 않고 오류 문구만 보여 줍니다. */ +export const isTooLong = (value: string, max: number) => value.trim().length > max; + +type FieldLabelProps = { + label: string; + /** 별표(*) 뒤에 붙는 설명. 예: (복수 선택 가능) */ + hint?: string; + required?: boolean; + /** true면 라벨을 더 진한 색(text/default/strong)으로 보여 줍니다. */ + strong?: boolean; +}; + +function FieldLabel({ label, hint, required = true, strong = false }: FieldLabelProps) { + return ( + + {label} + {required ? * : null} + {hint ? ` ${hint}` : null} + + ); +} + +export type TextFieldProps = Omit & FieldLabelProps; + +/** 위에 라벨이 붙은 입력칸 */ +export function TextField({ label, hint, required, strong, ...inputProps }: TextFieldProps) { + return ( + + + + + + + ); +} + +type ChipSelectFieldProps = FieldLabelProps & { + options: readonly T[]; + isSelected: (option: T) => boolean; + onPress: (option: T) => void; + /** true면 하나만 고르는 라디오, false면 여러 개 고르는 체크박스로 읽힙니다. */ + single?: boolean; + /** '기타'를 골랐을 때 칩 아래에 보여 줄 입력칸 */ + other?: { visible: boolean; value: string; onChangeText: (text: string) => void }; +}; + +/** 라벨 + 칩 묶음. '기타'를 고르면 아래에 직접 입력칸이 나타납니다. */ +export function ChipSelectField({ + label, + hint, + required, + strong, + options, + isSelected, + onPress, + single = false, + other, +}: ChipSelectFieldProps) { + return ( + + + + + + {options.map((option) => ( + onPress(option)} + /> + ))} + + {other?.visible ? ( + + + + ) : null} + + ); +} + +const s = StyleSheet.create({ + label: { + ...typography.body[5].semiBold, + color: semantic.text.default.neutral, + }, + labelStrong: { color: semantic.text.default.strong }, + required: { color: semantic.text.brand.assistive }, + textField: { gap: gap[8] }, + textLabel: { paddingHorizontal: padding[8] }, + selectField: { paddingVertical: padding[8], gap: gap[8] }, + selectLabel: { paddingHorizontal: gap[4] }, + chips: { flexDirection: 'row', flexWrap: 'wrap', gap: gap[8] }, + // 디자인에서 칩 묶음과 입력칸 사이가 10px입니다 (gap 8 + 2). + otherInput: { marginTop: unit[2] }, +}); diff --git a/src/features/tutoring/InviteScreen.tsx b/src/features/tutoring/InviteScreen.tsx new file mode 100644 index 0000000..f6e6f4f --- /dev/null +++ b/src/features/tutoring/InviteScreen.tsx @@ -0,0 +1,201 @@ +import addImage from '../../../assets/images/add.svg'; +import { Fragment, useState } from 'react'; +import { Pressable, StyleSheet, Text, View } from 'react-native'; +import { Image } from 'expo-image'; +import { ChipSelectField, TextField } from './FormFields'; +import type { TextFieldProps } from './FormFields'; +import { TutoringFormLayout, useSubmit } from './TutoringFormLayout'; +import { semantic } from '@/styles/colors'; +import { gap, lineWeight, padding, radius, unit } from '@/styles/measurement'; +import { typography } from '@/styles/typography'; +import { INVALID_PHONE_MESSAGE, formatPhone, isValidPhone } from '@/utils/phone'; + +const TITLES = ['어머님', '아버님', '보호자님'] as const; +const MAX_PARENTS = 2; + +type ParentTitle = (typeof TITLES)[number]; +type Parent = { phone: string; title: ParentTitle | null }; + +// TODO: 학부모 번호 입력 여부에 따라 문구가 바뀌는지 기획 확인이 필요합니다. 지금은 디자인 문구 그대로입니다. +const INVITE_SUMMARY = [ + { label: '학부모', value: '초대 링크 / 근황 보내지 않음' }, + { label: '학생', value: '초대 링크' }, + { label: '함께 보내요', value: '수업 계획서' }, +]; + +const emptyParent = (): Parent => ({ phone: '', title: null }); + +type PhoneFieldProps = Omit & { + value: string; + onChangeText: (value: string) => void; +}; + +/** 하이픈을 자동으로 넣고, 입력칸을 벗어났을 때 번호가 틀리면 오류 문구를 보여 주는 입력칸 */ +function PhoneField({ value, onChangeText, onBlur, ...props }: PhoneFieldProps) { + const [touched, setTouched] = useState(false); + const invalid = touched && value.length > 0 && !isValidPhone(value); + + return ( + onChangeText(formatPhone(text))} + onBlur={(e) => { + setTouched(true); + onBlur?.(e); + }} + errorMessage={invalid ? INVALID_PHONE_MESSAGE : undefined} + keyboardType="phone-pad" + placeholder="전화번호" + /> + ); +} + +/** T-05 과외 만들기 · 초대 (5/5 단계) */ +export function InviteScreen() { + const [parents, setParents] = useState([emptyParent()]); + const [studentPhone, setStudentPhone] = useState(''); + + const updateParent = (index: number, patch: Partial) => + setParents((prev) => prev.map((p, i) => (i === index ? { ...p, ...patch } : p))); + + // 첫 번째 학부모 번호는 필수, 나머지 번호는 입력했다면 올바른 형식이어야 합니다. + const optionalOk = (phone: string) => phone.length === 0 || isValidPhone(phone); + const canProceed = + isValidPhone(parents[0].phone) && + parents.slice(1).every((p) => optionalOk(p.phone)) && + optionalOk(studentPhone); + + // TODO: 저장·초대 링크 전송 API를 useSubmit 두 번째 인자로 넘기고, 성공하면 완료 화면으로 이동합니다. + const { submitting, failed, submit } = useSubmit(() => {}); + + return ( + + {parents.map((parent, index) => ( + + updateParent(index, { phone })} + /> + + parent.title === title} + onPress={(title) => updateParent(index, { title })} + /> + {index === parents.length - 1 && parents.length < MAX_PARENTS ? ( + setParents((prev) => [...prev, emptyParent()])} + style={({ pressed }) => [s.addButton, pressed && s.addButtonPressed]} + > + + 학부모 추가 (최대 2명) + + ) : null} + + + ))} + + + + + 이렇게 초대해요 + + {INVITE_SUMMARY.map((row, i) => ( + + {i > 0 ? : null} + + {row.label} + {row.value} + + + ))} + + {/* 전송 실패 토스트가 떠 있는 동안에는 디자인대로 안내 상자를 숨기고 그 자리에 토스트를 보여 줍니다. */} + {failed ? null : ( + + + { + '링크로 볼지 앱을 깔지는 각자 고르고, 초대를 수락하기 전에는\n아무것도 보내지 않아요.' + } + + + )} + + + ); +} + +const s = StyleSheet.create({ + addButton: { + height: 54, + flexDirection: 'row', + alignItems: 'center', + justifyContent: 'center', + gap: gap[8], + // 칩 묶음과 버튼 사이가 12px입니다 (칩 영역 아래 여백 8 + 4). + marginTop: unit[4], + paddingHorizontal: padding[12], + paddingVertical: padding[8], + borderRadius: radius.medium, + borderWidth: lineWeight.regular, + borderColor: semantic.border.default, + backgroundColor: semantic.surface.default, + }, + addButtonPressed: { backgroundColor: semantic.surface.disabled }, + addIcon: { width: 16, height: 16 }, + addLabel: { + ...typography.body[3].medium, + textAlign: 'center', + color: semantic.text.default.weak, + }, + inviteSection: { paddingVertical: padding[12], gap: gap[12] }, + sectionLabel: { + ...typography.body[5].semiBold, + paddingHorizontal: padding[4], + color: semantic.text.default.neutral, + }, + summary: { + gap: gap[12], + paddingHorizontal: padding[16], + paddingVertical: padding[12], + borderRadius: radius.medium, + backgroundColor: semantic.surface.subtle, + }, + summaryRow: { flexDirection: 'row', alignItems: 'center', justifyContent: 'space-between' }, + summaryLabel: { ...typography.body[4].semiBold, color: semantic.text.default.neutral }, + summaryValue: { ...typography.body[4].medium, color: semantic.text.default.weak }, + divider: { + height: lineWeight.subtle, + borderRadius: radius.small, + backgroundColor: semantic.border.default, + }, + notice: { + paddingHorizontal: padding[12], + paddingVertical: padding[8], + borderRadius: radius.small, + backgroundColor: semantic.surface.focused, + }, + noticeText: { ...typography.caption[1].medium, color: semantic.text.brand.assistive }, +}); diff --git a/src/features/tutoring/StudentInfoScreen.tsx b/src/features/tutoring/StudentInfoScreen.tsx new file mode 100644 index 0000000..eaa84a6 --- /dev/null +++ b/src/features/tutoring/StudentInfoScreen.tsx @@ -0,0 +1,89 @@ +import { useState } from 'react'; +import { router } from 'expo-router'; +import { ChipSelectField, TOO_LONG_MESSAGE, TextField, isTooLong } from './FormFields'; +import { TutoringFormLayout, useSubmit } from './TutoringFormLayout'; +import type { PrefillSource } from './TutoringFormLayout'; + +const GRADES = ['초6', '중1', '중2', '중3', '고1', '고2', '고3', '기타'] as const; +const SUBJECTS = ['국어', '영어', '수학', '과학', '사회', '기타'] as const; + +type Grade = (typeof GRADES)[number]; +type Subject = (typeof SUBJECTS)[number]; + +// 프로필 이름과 같은 기준입니다. +const NAME_MAX_LENGTH = 10; + +export type StudentInfoScreenProps = { + /** 없으면 안내 메시지를 보여 주지 않습니다. */ + prefillSource?: PrefillSource; +}; + +/** T-05 과외 만들기 · 학생 정보 (2/5 단계) */ +export function StudentInfoScreen({ prefillSource }: StudentInfoScreenProps) { + const [name, setName] = useState(''); + const [grade, setGrade] = useState(null); + const [otherGrade, setOtherGrade] = useState(''); + const [subjects, setSubjects] = useState([]); + const [otherSubject, setOtherSubject] = useState(''); + + const toggleSubject = (subject: Subject) => + setSubjects((prev) => + prev.includes(subject) ? prev.filter((v) => v !== subject) : [...prev, subject], + ); + + const otherSubjectSelected = subjects.includes('기타'); + const nameTooLong = isTooLong(name, NAME_MAX_LENGTH); + const canProceed = + name.trim().length > 0 && + !nameTooLong && + grade !== null && + (grade !== '기타' || otherGrade.trim().length > 0) && + subjects.length > 0 && + (!otherSubjectSelected || otherSubject.trim().length > 0); + + // TODO: 입력한 학생 정보를 다음 단계로 넘기거나 저장합니다. + const { submitting, submit } = useSubmit(() => + router.push({ + pathname: '/tutoring/textbook', + params: prefillSource ? { source: prefillSource } : {}, + }), + ); + + return ( + + + grade === g} + onPress={setGrade} + other={{ visible: grade === '기타', value: otherGrade, onChangeText: setOtherGrade }} + /> + subjects.includes(subject)} + onPress={toggleSubject} + other={{ + visible: otherSubjectSelected, + value: otherSubject, + onChangeText: setOtherSubject, + }} + /> + + ); +} diff --git a/src/features/tutoring/TextbookScreen.tsx b/src/features/tutoring/TextbookScreen.tsx new file mode 100644 index 0000000..d53e5f0 --- /dev/null +++ b/src/features/tutoring/TextbookScreen.tsx @@ -0,0 +1,70 @@ +import { useState } from 'react'; +import { ChipSelectField, TOO_LONG_MESSAGE, TextField, isTooLong } from './FormFields'; +import { TutoringFormLayout, useSubmit } from './TutoringFormLayout'; +import type { PrefillSource } from './TutoringFormLayout'; + +const PROGRESS_UNITS = ['Unit', '단원', 'Chapter', 'Page', '회', '기타'] as const; + +type ProgressUnit = (typeof PROGRESS_UNITS)[number]; + +// 학생 이름과 같은 기준입니다. +const TITLE_MAX_LENGTH = 10; + +export type TextbookScreenProps = { + /** 없으면 안내 메시지를 보여 주지 않습니다. */ + prefillSource?: PrefillSource; +}; + +/** T-05 과외 만들기 · 교재 (3/5 단계) */ +export function TextbookScreen({ prefillSource }: TextbookScreenProps) { + // TODO: 디자인 라벨은 "학생당 1~5권"이지만, 여러 권을 추가하는 화면이 아직 없어 한 권만 받습니다. + const [title, setTitle] = useState(''); + const [unit, setUnit] = useState(null); + const [otherUnit, setOtherUnit] = useState(''); + const [currentProgress, setCurrentProgress] = useState(''); + + const titleTooLong = isTooLong(title, TITLE_MAX_LENGTH); + const canProceed = + title.trim().length > 0 && + !titleTooLong && + unit !== null && + (unit !== '기타' || otherUnit.trim().length > 0); + + // TODO: 4단계 화면이 생기면 이동합니다. + const { submitting, submit } = useSubmit(() => {}); + + return ( + + + unit === u} + onPress={setUnit} + other={{ visible: unit === '기타', value: otherUnit, onChangeText: setOtherUnit }} + /> + setCurrentProgress(text.replace(/[^0-9]/g, ''))} + keyboardType="number-pad" + placeholder="지금 진도" + helperText="교재 내용은 저장하지 않고, 이름과 진도 단위만 써요." + /> + + ); +} diff --git a/src/features/tutoring/TutoringFormLayout.tsx b/src/features/tutoring/TutoringFormLayout.tsx new file mode 100644 index 0000000..034d4d3 --- /dev/null +++ b/src/features/tutoring/TutoringFormLayout.tsx @@ -0,0 +1,200 @@ +import arrowBackImage from '../../../assets/images/arrow_back.svg'; +import { useEffect, useState } from 'react'; +import type { ReactNode } from 'react'; +import { Platform, Pressable, ScrollView, StyleSheet, Text, View } from 'react-native'; +import { Image } from 'expo-image'; +import { router } from 'expo-router'; +import { SafeAreaView } from 'react-native-safe-area-context'; +import { ActionButton } from '@/components/ActionButton'; +import { Loading } from '@/components/Loading'; +import { ProgressBar } from '@/components/ProgressBar'; +import { semantic } from '@/styles/colors'; +import { gap, padding, radius } from '@/styles/measurement'; +import { typography } from '@/styles/typography'; + +export const TOTAL_STEPS = 5; + +/** 앞 단계에서 미리 채워 둔 정보의 출처. 출처에 따라 안내 문구가 달라집니다. */ +export type PrefillSource = 'lastTutoring' | 'curriculum'; + +const PREFILL_NOTICE: Record = { + lastTutoring: '지난 과외 계좌를 불러왔어요.', + curriculum: '커리큘럼에서 학생 정보, 교재, 요일을 채워두었어요', +}; + +export const isPrefillSource = (value: unknown): value is PrefillSource => + value === 'lastTutoring' || value === 'curriculum'; + +// TODO: 저장 API가 생기면 실제 요청으로 바꿉니다. 지금은 로딩 화면만 보여 줍니다. +const SUBMIT_PREVIEW_MS = 1500; +const ERROR_TOAST_MS = 3000; + +const previewRequest = () => new Promise((resolve) => setTimeout(resolve, SUBMIT_PREVIEW_MS)); + +/** + * "다음"을 누르면 request를 기다리는 동안 로딩을 보여 주고, 성공하면 onDone을 부릅니다. + * 실패하면 failed가 3초 동안 true가 됩니다. + */ +export function useSubmit(onDone: () => void, request: () => Promise = previewRequest) { + const [submitting, setSubmitting] = useState(false); + const [failed, setFailed] = useState(false); + + useEffect(() => { + if (!failed) return; + const timer = setTimeout(() => setFailed(false), ERROR_TOAST_MS); + return () => clearTimeout(timer); + }, [failed]); + + const submit = async () => { + if (submitting) return; + setFailed(false); + setSubmitting(true); + try { + await request(); + } catch { + setFailed(true); + return; + } finally { + setSubmitting(false); + } + onDone(); + }; + + return { submitting, failed, submit }; +} + +export type TutoringFormLayoutProps = { + step: number; + /** 없으면 안내 메시지를 보여 주지 않습니다. */ + prefillSource?: PrefillSource; + canProceed: boolean; + submitting: boolean; + onNext: () => void; + /** 하단 버튼 글자. 기본값은 "다음" */ + ctaLabel?: string; + /** false면 로딩 중에 가운데 로딩 카드 없이 버튼만 로딩으로 바뀝니다. */ + loadingOverlay?: boolean; + /** 값이 있으면 하단 버튼 위에 토스트로 보여 줍니다. */ + toast?: string; + children: ReactNode; +}; + +/** 과외 만들기 단계 화면의 공통 틀 (헤더, 진행 막대, 안내 메시지, 다음 버튼, 로딩) */ +export function TutoringFormLayout({ + step, + prefillSource, + canProceed, + submitting, + onNext, + ctaLabel = '다음', + loadingOverlay = true, + toast, + children, +}: TutoringFormLayoutProps) { + const back = () => { + if (router.canGoBack()) router.back(); + else router.replace('/home'); + }; + + return ( + + + + + + + + 과외 만들기 + + + + + + + + {prefillSource ? ( + + {PREFILL_NOTICE[prefillSource]} + + ) : null} + + {children} + + + + {toast ? ( + + + {toast} + + + ) : null} + { + if (canProceed) onNext(); + }} + /> + + + + + ); +} + +const s = StyleSheet.create({ + safe: { flex: 1, alignItems: 'center', backgroundColor: semantic.surface.input }, + // 웹에서는 휴대폰 너비(390)로 가운데 정렬하고, 상태바 높이만큼 위를 띄웁니다. + phone: { flex: 1, width: '100%', maxWidth: 390, paddingTop: Platform.OS === 'web' ? 44 : 0 }, + navBar: { + flexDirection: 'row', + alignItems: 'center', + justifyContent: 'space-between', + paddingHorizontal: padding[24], + paddingVertical: padding[12], + }, + icon: { width: 24, height: 24 }, + title: { + ...typography.body[1].bold, + textAlign: 'center', + color: semantic.text.default.strong, + }, + content: { + paddingHorizontal: padding[24], + gap: gap[8], + }, + inlineMessage: { + flexDirection: 'row', + alignItems: 'center', + gap: gap[4], + paddingHorizontal: padding[12], + paddingVertical: padding[8], + borderRadius: radius.small, + backgroundColor: semantic.surface.focused, + }, + inlineMessageText: { + ...typography.caption[1].medium, + color: semantic.text.brand.assistive, + }, + form: { paddingVertical: padding[12], gap: gap[20] }, + // 토스트 아래쪽이 버튼 위쪽에서 12px 떨어지도록 CTA 위로 띄웁니다. (토스트 32 + 12 - CTA 위 여백 20) + toastSlot: { position: 'absolute', top: -24, left: 0, right: 0, alignItems: 'center' }, + toast: { + backgroundColor: semantic.surface.inverse, + borderRadius: radius.full, + paddingHorizontal: padding[12], + paddingVertical: padding[8], + // PushBanner와 같은 그림자입니다. + boxShadow: '0px 4px 8px rgba(0, 0, 0, 0.18)', + elevation: 6, + }, + toastText: { ...typography.caption[1].regular, color: semantic.text.default.inverse }, + cta: { + paddingHorizontal: padding[24], + paddingTop: padding[20], + paddingBottom: padding[20], + backgroundColor: semantic.surface.input, + }, +}); diff --git a/src/utils/phone.ts b/src/utils/phone.ts new file mode 100644 index 0000000..52cfc13 --- /dev/null +++ b/src/utils/phone.ts @@ -0,0 +1,14 @@ +/** 숫자만 남기고 010-1234-5678 꼴(3-4-4)로 하이픈을 넣습니다. 11자리를 넘는 숫자는 버립니다. */ +export function formatPhone(input: string): string { + const digits = input.replace(/\D/g, '').slice(0, 11); + if (digits.length <= 3) return digits; + if (digits.length <= 7) return `${digits.slice(0, 3)}-${digits.slice(3)}`; + return `${digits.slice(0, 3)}-${digits.slice(3, 7)}-${digits.slice(7)}`; +} + +/** 01X 뒤에 8자리가 붙은 11자리 휴대폰 번호인지 봅니다. */ +export function isValidPhone(input: string): boolean { + return /^01\d{9}$/.test(input.replace(/\D/g, '')); +} + +export const INVALID_PHONE_MESSAGE = '휴대폰 번호는 8자리로 입력해주세요';