Skip to content

Commit

Permalink
feat: add optional props to PhoneInput
Browse files Browse the repository at this point in the history
  • Loading branch information
ChaeyeonAhn committed Sep 30, 2024
1 parent 360e075 commit a2f6a0a
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions packages/web/src/common/components/Forms/PhoneInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,10 @@ const InputWrapper = styled.div`

// Component
const PhoneInput2: React.FC<
PhoneInputProps & { setErrorStatus?: (hasError: boolean) => void }
PhoneInputProps & {
setErrorStatus?: (hasError: boolean) => void;
optional?: boolean;
}
> = ({
label = "",
placeholder,
Expand All @@ -95,6 +98,7 @@ const PhoneInput2: React.FC<
handleChange = () => {}, // setValue
onChange = undefined, // display results (complicated)
setErrorStatus = () => {},
optional = false,
...props
}) => {
const formCtx = useForm({
Expand All @@ -118,7 +122,7 @@ const PhoneInput2: React.FC<
/^(\d{3}-\d{4}-\d{4})$/.test(value) ||
/^\d*$/.test(value.replace(/-/g, ""));

if (!value) {
if (!optional && !value) {
formCtx.setError("phoneNumber", {
message: "필수로 채워야 하는 항목입니다",
});
Expand Down

0 comments on commit a2f6a0a

Please sign in to comment.