Refactors useLocale (#908)

* Removes unused component

* Refactors useLocale

We don't need to pass the locale prop everywhere

* Fixes syntax error

* Adds warning for missing localeProps

* Simplify i18n utils

* Update components/I18nLanguageHandler.tsx

Co-authored-by: Mihai C <[email protected]>

* Type fixes

Co-authored-by: Mihai C <[email protected]>
This commit is contained in:
Omar LópezandMihai C authored and GitHub committed 2021-10-12 13:11:33 +00:00
1 parent 7dd6fdde7a
commit cfd70172f0
35 files changed
+366 -440

No files matched your search

+7 -5
View File
@@ -11,7 +11,6 @@ import { useSlots } from "@lib/hooks/useSlots";
import Loader from "@components/Loader";
type AvailableTimesProps = {
localeProp: string;
workingHours: {
days: number[];
startTime: number;
@@ -29,7 +28,6 @@ type AvailableTimesProps = {
};
const AvailableTimes: FC<AvailableTimesProps> = ({
localeProp,
date,
eventLength,
eventTypeId,
@@ -39,7 +37,7 @@ const AvailableTimes: FC<AvailableTimesProps> = ({
users,
schedulingType,
}) => {
const { t } = useLocale({ localeProp: localeProp });
const { t } = useLocale();
const router = useRouter();
const { rescheduleUid } = router.query;
@@ -68,7 +66,11 @@ const AvailableTimes: FC<AvailableTimesProps> = ({
{!loading &&
slots?.length > 0 &&
slots.map((slot) => {
const bookingUrl = {
type BookingURL = {
pathname: string;
query: Record<string, string | number | string[] | undefined>;
};
const bookingUrl: BookingURL = {
pathname: "book",
query: {
...router.query,
@@ -78,7 +80,7 @@ const AvailableTimes: FC<AvailableTimesProps> = ({
};
if (rescheduleUid) {
bookingUrl.query.rescheduleUid = rescheduleUid;
bookingUrl.query.rescheduleUid = rescheduleUid as string;
}
if (schedulingType === SchedulingType.ROUND_ROBIN) {
+3 -3
View File
@@ -6,7 +6,7 @@ import { useMutation } from "react-query";
import { HttpError } from "@lib/core/http/error";
import { inferQueryOutput, trpc } from "@lib/trpc";
import TableActions from "@components/ui/TableActions";
import TableActions, { ActionType } from "@components/ui/TableActions";
type BookingItem = inferQueryOutput<"viewer.bookings">[number];
@@ -34,7 +34,7 @@ function BookingListItem(booking: BookingItem) {
const isUpcoming = new Date(booking.endTime) >= new Date();
const isCancelled = booking.status === BookingStatus.CANCELLED;
const pendingActions = [
const pendingActions: ActionType[] = [
{
id: "reject",
label: "Reject",
@@ -52,7 +52,7 @@ function BookingListItem(booking: BookingItem) {
},
];
const bookedActions = [
const bookedActions: ActionType[] = [
{
id: "cancel",
label: "Cancel",
+1 -2
View File
@@ -14,7 +14,6 @@ dayjs.extend(utc);
dayjs.extend(timezone);
const DatePicker = ({
localeProp,
weekStart,
onDatePicked,
workingHours,
@@ -28,7 +27,7 @@ const DatePicker = ({
periodCountCalendarDays,
minimumBookingNotice,
}) => {
const { t } = useLocale({ localeProp: localeProp });
const { t } = useLocale();
const [days, setDays] = useState<({ disabled: boolean; date: number } | null)[]>([]);
const [selectedMonth, setSelectedMonth] = useState<number | null>(
+1 -2
View File
@@ -9,7 +9,6 @@ import { useLocale } from "@lib/hooks/useLocale";
import { is24h, timeZone } from "../../lib/clock";
type Props = {
localeProp: string;
onSelectTimeZone: (selectedTimeZone: string) => void;
onToggle24hClock: (is24hClock: boolean) => void;
};
@@ -17,7 +16,7 @@ type Props = {
const TimeOptions: FC<Props> = (props) => {
const [selectedTimeZone, setSelectedTimeZone] = useState("");
const [is24hClock, setIs24hClock] = useState(false);
const { t } = useLocale({ localeProp: props.localeProp });
const { t } = useLocale();
useEffect(() => {
setIs24hClock(is24h());
@@ -30,11 +30,11 @@ dayjs.extend(customParseFormat);
type Props = AvailabilityTeamPageProps | AvailabilityPageProps;
const AvailabilityPage = ({ profile, eventType, workingHours, localeProp }: Props) => {
const AvailabilityPage = ({ profile, eventType, workingHours }: Props) => {
const router = useRouter();
const { rescheduleUid } = router.query;
const { isReady } = useTheme(profile.theme);
const { t, locale } = useLocale({ localeProp });
const { t } = useLocale();
const selectedDate = useMemo(() => {
const dateString = asStringOrNull(router.query.date);
@@ -188,7 +188,6 @@ const AvailabilityPage = ({ profile, eventType, workingHours, localeProp }: Prop
<p className="mt-3 mb-8 text-gray-600 dark:text-gray-200">{eventType.description}</p>
</div>
<DatePicker
localeProp={locale}
date={selectedDate}
periodType={eventType?.periodType}
periodStartDate={eventType?.periodStartDate}
@@ -208,7 +207,6 @@ const AvailabilityPage = ({ profile, eventType, workingHours, localeProp }: Prop
{selectedDate && (
<AvailableTimes
localeProp={locale}
workingHours={workingHours}
timeFormat={timeFormat}
minimumBookingNotice={eventType.minimumBookingNotice}
@@ -241,11 +239,7 @@ const AvailabilityPage = ({ profile, eventType, workingHours, localeProp }: Prop
)}
</Collapsible.Trigger>
<Collapsible.Content>
<TimeOptions
localeProp={locale}
onSelectTimeZone={handleSelectTimeZone}
onToggle24hClock={handleToggle24hClock}
/>
<TimeOptions onSelectTimeZone={handleSelectTimeZone} onToggle24hClock={handleToggle24hClock} />
</Collapsible.Content>
</Collapsible.Root>
);
+3 -13
View File
@@ -13,8 +13,6 @@ import { stringify } from "querystring";
import { useCallback, useEffect, useState } from "react";
import { FormattedNumber, IntlProvider } from "react-intl";
import { ReactMultiEmail } from "react-multi-email";
import PhoneInput from "react-phone-number-input";
import "react-phone-number-input/style.css";
import { createPaymentLink } from "@ee/lib/stripe/client";
@@ -30,6 +28,7 @@ import { BookingCreateBody } from "@lib/types/booking";
import AvatarGroup from "@components/ui/AvatarGroup";
import { Button } from "@components/ui/Button";
import PhoneInput from "@components/ui/form/PhoneInput";
import { BookPageProps } from "../../../pages/[user]/book";
import { TeamBookingPageProps } from "../../../pages/team/[slug]/book";
@@ -37,7 +36,7 @@ import { TeamBookingPageProps } from "../../../pages/team/[slug]/book";
type BookingPageProps = BookPageProps | TeamBookingPageProps;
const BookingPage = (props: BookingPageProps) => {
const { t } = useLocale({ localeProp: props.localeProp });
const { t } = useLocale();
const router = useRouter();
const { rescheduleUid } = router.query;
const { isReady } = useTheme(props.profile.theme);
@@ -319,16 +318,7 @@ const BookingPage = (props: BookingPageProps) => {
{t("phone_number")}
</label>
<div className="mt-1">
<PhoneInput
name="phone"
placeholder={t("enter_phone_number")}
id="phone"
required
className="block w-full border-gray-300 rounded-md shadow-sm dark:bg-black dark:text-white dark:border-gray-900 focus:ring-black focus:border-black sm:text-sm"
onChange={() => {
/* DO NOT REMOVE: Callback required by PhoneInput, comment added to satisfy eslint:no-empty-function */
}}
/>
<PhoneInput name="phone" placeholder={t("enter_phone_number")} id="phone" required />
</div>
</div>
)}