Skip to content

Commit

Permalink
feat: add optional to PhoneInput
Browse files Browse the repository at this point in the history
  • Loading branch information
ChaeyeonAhn committed Sep 30, 2024
1 parent f40977a commit bdfa0e9
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions packages/web/src/common/components/Forms/PhoneInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -84,14 +84,15 @@ const InputWrapper = styled.div`
`;

// Component
const PhoneInput: React.FC<PhoneInputProps> = ({
const PhoneInput: React.FC<PhoneInputProps & { optional?: boolean }> = ({
label = "",
placeholder,
disabled = false,
value = "",
handleChange = () => {}, // setValue
setErrorStatus = () => {},
onChange = undefined, // display results (complicated)
optional = false,
...props
}) => {
const [error, setError] = useState("");
Expand All @@ -117,7 +118,7 @@ const PhoneInput: React.FC<PhoneInputProps> = ({
const isValidFormat =
/^(\d{3}-\d{4}-\d{4})$/.test(value) ||
/^\d*$/.test(value.replace(/-/g, ""));
if (!value) {
if (!optional && !value) {
setError("필수로 채워야 하는 항목입니다");
} else if (!isValidFormat) {
setError("숫자만 입력 가능합니다");
Expand Down

0 comments on commit bdfa0e9

Please sign in to comment.