Users Phone Number Option (#2669)

* Users Phone Number Option

* Implemented improvments

* Add validation to form

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
Co-authored-by: zomars <[email protected]>
This commit is contained in:
authored and GitHub committed 2022-05-16 09:50:12 -06:00
1 parent 3c37c2e774
commit 7fd149fd2e
7 files changed
+72 -6

No files matched your search

+56 -3
View File
@@ -21,6 +21,7 @@ import classNames from "classnames";
import dayjs from "dayjs";
import timezone from "dayjs/plugin/timezone";
import utc from "dayjs/plugin/utc";
import { isValidPhoneNumber, parsePhoneNumber } from "libphonenumber-js";
import { GetServerSidePropsContext } from "next";
import { useRouter } from "next/router";
import React, { useEffect, useState } from "react";
@@ -70,6 +71,7 @@ import CheckboxField from "@components/ui/form/CheckboxField";
import CheckedSelect from "@components/ui/form/CheckedSelect";
import { DateRangePicker } from "@components/ui/form/DateRangePicker";
import MinutesField from "@components/ui/form/MinutesField";
import PhoneInput from "@components/ui/form/PhoneInput";
import Select from "@components/ui/form/Select";
import * as RadioArea from "@components/ui/form/radio-area";
import WebhookListContainer from "@components/webhook/WebhookListContainer";
@@ -422,6 +424,34 @@ const EventTypePage = (props: inferSSRProps<typeof getServerSideProps>) => {
</div>
</div>
);
case LocationType.UserPhone:
return (
<div>
<label htmlFor="phonenumber" className="block text-sm font-medium text-gray-700">
{t("set_your_phone_number")}
</label>
<div className="mt-1">
<PhoneInput
control={locationFormMethods.control}
name="locationPhoneNumber"
required
id="locationPhoneNumber"
placeholder={t("host_phone_number")}
rules={{}}
defaultValue={
formMethods
.getValues("locations")
.find((location) => location.type === LocationType.UserPhone)?.hostPhoneNumber
}
/>
{locationFormMethods.formState.errors.locationPhoneNumber && (
<p className="mt-1 text-red-500">
{locationFormMethods.formState.errors.locationPhoneNumber.message}
</p>
)}
</div>
</div>
);
case LocationType.Phone:
return <p className="text-sm">{t("cal_invitee_phone_number_scheduling")}</p>;
/* TODO: Render this dynamically from App Store */
@@ -509,7 +539,7 @@ const EventTypePage = (props: inferSSRProps<typeof getServerSideProps>) => {
hidden: boolean;
hideCalendarNotes: boolean;
hashedLink: string | undefined;
locations: { type: LocationType; address?: string; link?: string }[];
locations: { type: LocationType; address?: string; link?: string; hostPhoneNumber?: string }[];
customInputs: EventTypeCustomInput[];
users: string[];
schedule: number;
@@ -542,11 +572,16 @@ const EventTypePage = (props: inferSSRProps<typeof getServerSideProps>) => {
const locationFormSchema = z.object({
locationType: z.string(),
locationAddress: z.string().optional(),
locationPhoneNumber: z
.string()
.refine((val) => isValidPhoneNumber(val))
.optional(),
locationLink: z.string().url().optional(), // URL validates as new URL() - which requires HTTPS:// In the input field
});
const locationFormMethods = useForm<{
locationType: LocationType;
locationPhoneNumber?: string;
locationAddress?: string; // TODO: We should validate address or fetch the address from googles api to see if its valid?
locationLink?: string; // Currently this only accepts links that are HTTPS://
}>({
@@ -565,7 +600,11 @@ const EventTypePage = (props: inferSSRProps<typeof getServerSideProps>) => {
if (e?.value) {
const newLocationType: LocationType = e.value;
locationFormMethods.setValue("locationType", newLocationType);
if (newLocationType === LocationType.InPerson || newLocationType === LocationType.Link) {
if (
newLocationType === LocationType.InPerson ||
newLocationType === LocationType.Link ||
newLocationType === LocationType.UserPhone
) {
openLocationModal(newLocationType);
} else {
addLocation(newLocationType);
@@ -602,6 +641,16 @@ const EventTypePage = (props: inferSSRProps<typeof getServerSideProps>) => {
/>
</div>
)}
{location.type === LocationType.UserPhone && (
<div className="flex flex-grow items-center">
<PhoneIcon className="h-6 w-6" />
<input
disabled
className="w-full border-0 bg-transparent text-sm ltr:ml-2 rtl:mr-2"
value={location.hostPhoneNumber}
/>
</div>
)}
{location.type === LocationType.Phone && (
<div className="flex flex-grow items-center">
<PhoneIcon className="h-6 w-6" />
@@ -869,6 +918,7 @@ const EventTypePage = (props: inferSSRProps<typeof getServerSideProps>) => {
locationFormMethods.setValue("locationType", location.type);
locationFormMethods.unregister("locationLink");
locationFormMethods.unregister("locationAddress");
locationFormMethods.unregister("locationPhoneNumber");
openLocationModal(location.type);
}}
aria-label={t("edit")}
@@ -1925,7 +1975,9 @@ const EventTypePage = (props: inferSSRProps<typeof getServerSideProps>) => {
if (newLocation === LocationType.Link) {
details = { link: values.locationLink };
}
if (newLocation === LocationType.UserPhone) {
details = { hostPhoneNumber: values.locationPhoneNumber };
}
addLocation(newLocation, details);
setShowLocationModal(false);
}}>
@@ -1946,6 +1998,7 @@ const EventTypePage = (props: inferSSRProps<typeof getServerSideProps>) => {
locationFormMethods.setValue("locationType", val.value);
locationFormMethods.unregister("locationLink");
locationFormMethods.unregister("locationAddress");
locationFormMethods.unregister("locationPhoneNumber");
setSelectedLocation(val);
}
}}