Skip to content

Commit

Permalink
Simplify phone input
Browse files Browse the repository at this point in the history
  • Loading branch information
james-otten committed Apr 21, 2024
1 parent 3dcc7e1 commit 3dd3ad2
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions components/JoinForm/JoinForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@

import { JoinFormInput, submitJoinForm } from "@/app/api";
import 'react-phone-number-input/style.css';
import PhoneInput from 'react-phone-number-input';
import PhoneInput from 'react-phone-number-input/input';
import { E164Number } from 'libphonenumber-js/core';
import { toastErrorMessage } from "@/app/utils/toastErrorMessage";
import { ToastContainer, toast } from 'react-toastify';
import 'react-toastify/dist/ReactToastify.css';
import { formatPhoneNumberIntl, parsePhoneNumber } from 'react-phone-number-input'

import styles from './JoinForm.module.scss'

Expand All @@ -31,6 +32,13 @@ const JoinForm = () => {
data[key] = value === 'on' ? true : false;
} else if (key === 'zip') {
data[key] = Number(value);
} else if (key === 'phone') {
const parsedPhone = parsePhoneNumber(value as string, "US");
if(parsedPhone?.number) {
data[key] = formatPhoneNumberIntl(parsedPhone?.number)
} else {
data[key] = value;
}
} else {
data[key] = value;
}
Expand Down Expand Up @@ -102,7 +110,6 @@ const JoinForm = () => {
name="phone"
placeholder="Phone Number"
defaultCountry="US"
international={true}
value={phoneNumber}
onChange={setPhoneNumber}/>
</div>
Expand Down

0 comments on commit 3dd3ad2

Please sign in to comment.