diff --git a/apps/webservice/package.json b/apps/webservice/package.json index db34e83b..d7db3e46 100644 --- a/apps/webservice/package.json +++ b/apps/webservice/package.json @@ -26,7 +26,6 @@ "@ctrlplane/validators": "workspace:*", "@hookform/resolvers": "^3.3.4", "@icons-pack/react-simple-icons": "^10.0.0", - "@internationalized/date": "^3.5.4", "@monaco-editor/react": "^4.6.0", "@next/bundle-analyzer": "^14.2.13", "@octokit/auth-app": "^7.1.0", diff --git a/apps/webservice/src/app/[workspaceSlug]/(app)/_components/environment-drawer/Overview.tsx b/apps/webservice/src/app/[workspaceSlug]/(app)/_components/environment-drawer/Overview.tsx index 51d22c31..a7ebf0c8 100644 --- a/apps/webservice/src/app/[workspaceSlug]/(app)/_components/environment-drawer/Overview.tsx +++ b/apps/webservice/src/app/[workspaceSlug]/(app)/_components/environment-drawer/Overview.tsx @@ -31,17 +31,6 @@ type OverviewProps = { environment: SCHEMA.Environment; }; -const isUsing12HourClock = (): boolean => { - const date = new Date(); - const options: Intl.DateTimeFormatOptions = { - hour: "numeric", - }; - const formattedTime = new Intl.DateTimeFormat(undefined, options).format( - date, - ); - return formattedTime.includes("AM") || formattedTime.includes("PM"); -}; - export const Overview: React.FC = ({ environment }) => { const expiresAt = environment.expiresAt ?? undefined; const defaultValues = { ...environment, expiresAt }; @@ -103,7 +92,6 @@ export const Overview: React.FC = ({ environment }) => { value={value} onChange={onChange} granularity="minute" - hourCycle={isUsing12HourClock() ? 12 : 24} className="w-60" /> -
{title}
- - - - - ); -} - -interface CalendarGridProps { - state: CalendarState; -} - -function CalendarGrid({ state, ...props }: CalendarGridProps) { - const { locale } = useLocale(); - const { gridProps, headerProps, weekDays } = useCalendarGrid(props, state); - - // Get the number of weeks in the month so we can render the proper number of rows. - const weeksInMonth = getWeeksInMonth(state.visibleRange.start, locale); - - return ( - - - - {weekDays.map((day, index) => ( - - ))} - - - - {[...new Array(weeksInMonth).keys()].map((weekIndex) => ( - - {state - .getDatesInWeek(weekIndex) - .map((date, i) => - date ? ( - - ) : ( - - ))} - -
- {day} -
- ), - )} -
- ); -} - -interface CalendarCellProps { - state: CalendarState; - date: CalendarDate; -} - -function CalendarCell({ state, date }: CalendarCellProps) { - const ref = React.useRef(null); - const { - cellProps, - buttonProps, - isSelected, - isOutsideVisibleRange, - isDisabled, - formattedDate, - } = useCalendarCell({ date }, state, ref); - - const isToday = useMemo(() => { - const timezone = getLocalTimeZone(); - return _isToday(date, timezone); - }, [date]); - - return ( - - - - ); -} - -export { Calendar }; diff --git a/packages/ui/src/date-time-picker/date-field.tsx b/packages/ui/src/date-time-picker/date-field.tsx deleted file mode 100644 index 10957b43..00000000 --- a/packages/ui/src/date-time-picker/date-field.tsx +++ /dev/null @@ -1,53 +0,0 @@ -"use client"; - -import type { AriaDatePickerProps, DateValue } from "react-aria"; -import { useRef } from "react"; -import { createCalendar } from "@internationalized/date"; -import { useDateField, useLocale } from "react-aria"; -import { useDateFieldState } from "react-stately"; - -import { cn } from "../index"; -import { DateSegment } from "./date-segment"; - -function DateField( - props: AriaDatePickerProps & { variant?: string }, -) { - const ref = useRef(null); - - const { locale } = useLocale(); - const state = useDateFieldState({ - ...props, - locale, - createCalendar, - }); - const { fieldProps } = useDateField(props, state, ref); - - return ( -
- {state.segments.map((segment, i) => ( - - ))} - {state.validationState === "invalid" && ( - - )} -
- ); -} - -export { DateField }; diff --git a/packages/ui/src/date-time-picker/date-segment.tsx b/packages/ui/src/date-time-picker/date-segment.tsx deleted file mode 100644 index 76f1ac42..00000000 --- a/packages/ui/src/date-time-picker/date-segment.tsx +++ /dev/null @@ -1,42 +0,0 @@ -"use client"; - -import type { - DateFieldState, - DateSegment as IDateSegment, -} from "react-stately"; -import { useRef } from "react"; -import { useDateSegment } from "react-aria"; - -import { cn } from "../index"; - -interface DateSegmentProps { - segment: IDateSegment; - state: DateFieldState; - textxs?: boolean; -} - -function DateSegment({ segment, state, textxs }: DateSegmentProps) { - const ref = useRef(null); - - const { - segmentProps: { ...segmentProps }, - } = useDateSegment(segment, state, ref); - - return ( -
- {segment.text} -
- ); -} - -export { DateSegment }; diff --git a/packages/ui/src/date-time-picker/date-time-picker.tsx b/packages/ui/src/date-time-picker/date-time-picker.tsx deleted file mode 100644 index 565d1bc6..00000000 --- a/packages/ui/src/date-time-picker/date-time-picker.tsx +++ /dev/null @@ -1,85 +0,0 @@ -"use client"; - -import type { DateValue } from "react-aria"; -import type { DatePickerStateOptions } from "react-stately"; -import React, { useRef, useState } from "react"; -import { IconCalendar } from "@tabler/icons-react"; -import { useButton, useDatePicker, useInteractOutside } from "react-aria"; -import { useDatePickerState } from "react-stately"; - -import { Button } from "../button"; -import { cn } from "../index"; -import { Popover, PopoverContent, PopoverTrigger } from "../popover"; -import { Calendar } from "./calendar"; -import { DateField } from "./date-field"; -import { TimeField } from "./time-field"; -import { useForwardedRef } from "./useForwardedRef"; - -const DateTimePicker = React.forwardRef< - HTMLDivElement, - DatePickerStateOptions & { variant?: string } ->((props, forwardedRef) => { - const ref = useForwardedRef(forwardedRef); - const buttonRef = useRef(null); - const contentRef = useRef(null); - - const [open, setOpen] = useState(false); - - const state = useDatePickerState(props); - const { - groupProps, - fieldProps, - buttonProps: _buttonProps, - dialogProps, - calendarProps, - } = useDatePicker(props, state, ref); - const { buttonProps } = useButton(_buttonProps, buttonRef); - useInteractOutside({ - ref: contentRef, - onInteractOutside: () => { - setOpen(false); - }, - }); - - return ( -
- - - - - - -
- - {state.hasTime && ( - state.setTimeValue(value)} - /> - )} -
-
-
-
- ); -}); - -DateTimePicker.displayName = "DateTimePicker"; - -export { DateTimePicker }; diff --git a/packages/ui/src/date-time-picker/time-field.tsx b/packages/ui/src/date-time-picker/time-field.tsx deleted file mode 100644 index 1217dd21..00000000 --- a/packages/ui/src/date-time-picker/time-field.tsx +++ /dev/null @@ -1,42 +0,0 @@ -"use client"; - -import type { AriaTimeFieldProps, TimeValue } from "react-aria"; -import { useRef } from "react"; -import { useLocale, useTimeField } from "react-aria"; -import { useTimeFieldState } from "react-stately"; - -import { cn } from "../index"; -import { DateSegment } from "./date-segment"; - -function TimeField(props: AriaTimeFieldProps) { - const ref = useRef(null); - - const { locale } = useLocale(); - const state = useTimeFieldState({ - ...props, - locale, - }); - const { fieldProps } = useTimeField(props, state, ref); - - return ( -
- {state.segments.map((segment, i) => ( - - ))} -
- ); -} - -export { TimeField }; diff --git a/packages/ui/src/date-time-picker/useForwardedRef.tsx b/packages/ui/src/date-time-picker/useForwardedRef.tsx deleted file mode 100644 index 7160cce9..00000000 --- a/packages/ui/src/date-time-picker/useForwardedRef.tsx +++ /dev/null @@ -1,17 +0,0 @@ -import type React from "react"; -import { useEffect, useRef } from "react"; - -export function useForwardedRef(ref: React.ForwardedRef) { - const innerRef = useRef(null); - - useEffect(() => { - if (!ref) return; - if (typeof ref === "function") { - ref(innerRef.current); - return; - } - ref.current = innerRef.current; - }); - - return innerRef; -} diff --git a/packages/ui/src/datetime-picker.tsx b/packages/ui/src/datetime-picker.tsx index acba80d0..72d709d7 100644 --- a/packages/ui/src/datetime-picker.tsx +++ b/packages/ui/src/datetime-picker.tsx @@ -658,12 +658,21 @@ TimePicker.displayName = "TimePicker"; type Granularity = "day" | "hour" | "minute" | "second"; +const getHourCycle = (): 12 | 24 => { + const date = new Date(); + const options: Intl.DateTimeFormatOptions = { + hour: "numeric", + }; + const formattedTime = new Intl.DateTimeFormat(undefined, options).format( + date, + ); + return formattedTime.includes("AM") || formattedTime.includes("PM") ? 12 : 24; +}; + type DateTimePickerProps = { value?: Date; onChange?: (date: Date | undefined) => void; disabled?: boolean; - /** showing `AM/PM` or not. */ - hourCycle?: 12 | 24; placeholder?: string; /** * The year range will be: `This year + yearRange` and `this year - yearRange`. @@ -701,7 +710,6 @@ const DateTimePicker = React.forwardRef< locale = enUS, value, onChange, - hourCycle = 24, yearRange = 50, disabled = false, displayFormat, @@ -741,6 +749,8 @@ const DateTimePicker = React.forwardRef< [value], ); + const hourCycle = getHourCycle(); + const initHourFormat = { hour24: displayFormat?.hour24 ?? diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 2e1c9651..70e34c1d 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -498,9 +498,6 @@ importers: '@icons-pack/react-simple-icons': specifier: ^10.0.0 version: 10.1.0(react@18.3.1) - '@internationalized/date': - specifier: ^3.5.4 - version: 3.5.6 '@monaco-editor/react': specifier: ^4.6.0 version: 4.6.0(monaco-editor@0.52.0)(react-dom@18.3.1(react@18.3.1))(react@18.3.1)