diff --git a/apps/studio/components/interfaces/Auth/AuthProvidersForm/FormField.tsx b/apps/studio/components/interfaces/Auth/AuthProvidersForm/FormField.tsx index 3baabe74351..4f7d0cf7412 100644 --- a/apps/studio/components/interfaces/Auth/AuthProvidersForm/FormField.tsx +++ b/apps/studio/components/interfaces/Auth/AuthProvidersForm/FormField.tsx @@ -1,52 +1,86 @@ import { Markdown } from 'components/interfaces/Markdown' -import { DatePicker } from 'components/ui/DatePicker' -import dayjs from 'dayjs' +import { format } from 'date-fns' import { BASE_PATH } from 'lib/constants' -import { Eye, EyeOff } from 'lucide-react' -import { useEffect, useState } from 'react' +import { CalendarIcon, ExternalLink } from 'lucide-react' +import { type Control } from 'react-hook-form' import ReactMarkdown from 'react-markdown' -import { Button, Input, InputNumber, Listbox, Toggle } from 'ui' -import { InfoTooltip } from 'ui-patterns/info-tooltip' +import { + Button, + Calendar, + FormControl_Shadcn_, + FormField_Shadcn_, + Input_Shadcn_, + Popover_Shadcn_, + PopoverContent_Shadcn_, + PopoverTrigger_Shadcn_, + PrePostTab, + Select_Shadcn_, + SelectContent_Shadcn_, + SelectItem_Shadcn_, + SelectTrigger_Shadcn_, + SelectValue_Shadcn_, + Separator, + SheetSection, + Switch, + Textarea, + useWatch_Shadcn_, +} from 'ui' +import { Input as DataInput } from 'ui-patterns/DataInputs/Input' +import { FormItemLayout } from 'ui-patterns/form/FormItemLayout/FormItemLayout' import type { Enum } from './AuthProvidersForm.types' interface FormFieldProps { + projectRef: string | undefined + organizationSlug: string | undefined name: string properties: any - formValues: any - setFieldValue: (field: string, v: any) => any + control: Control + hasAccess: boolean disabled?: boolean } -function formatDate(date: Date): string { - return dayjs(date).format('dddd, MMMM D, YYYY HH:mm:ss Z') -} - const FormField = ({ + projectRef, name, properties, - formValues, - disabled = false, - setFieldValue, + organizationSlug, + control, + hasAccess, + disabled: disabledProp, }: FormFieldProps) => { - const [hidden, setHidden] = useState(!!properties.isSecret) - const [dateAsText, setDateAsText] = useState( - formValues[name] ? formatDate(new Date(formValues[name])) : '' - ) + const { description: originalDescription } = properties + let description = originalDescription - useEffect(() => { - if (properties.show && properties.show.key && !formValues[properties.show.key]) { - setFieldValue(name, '') - setDateAsText('') - } - }, [properties.show && properties.show.key && !formValues[properties.show.key]]) + if (originalDescription && projectRef) { + description = originalDescription.replace( + /\(\.\.\/auth\/(.*?)\)/g, + `(/project/${projectRef}/auth/$1)` + ) + } + + const fieldValue = useWatch_Shadcn_({ control, name }) + if (!hasAccess) { + const planMessage = organizationSlug + ? `Only available on [Pro plan](/org/${organizationSlug}/billing?panel=subscriptionPlan) and above.` + : '' + description = originalDescription ? `${originalDescription} ${planMessage}` : planMessage + } + const disabled = + disabledProp || (properties.type === 'boolean' ? !hasAccess && !fieldValue : !hasAccess) + + const showValue = useWatch_Shadcn_({ + control, + name: properties.show?.key, + disabled: properties.show == null, + }) if (properties.show) { if (properties.show.matches) { - if (!properties.show.matches.includes(formValues[properties.show.key])) { + if (!properties.show.matches.includes(showValue)) { return null } - } else if (!formValues[properties.show.key]) { + } else if (!showValue) { return null } } @@ -54,241 +88,304 @@ const FormField = ({ switch (properties.type) { case 'datetime': return ( - - {properties.descriptionOptional} - - ) : null - } - descriptionText={ - properties.description ? ( - - {properties.description} - - ) : null - } - actions={ - { - if (date && date.to) { - setFieldValue(name, date.to) - setDateAsText(formatDate(new Date(date.to))) - } else { - setDateAsText('') - setFieldValue(name, '') - } - }} - > - Pick - - } - /> + <> + + ( + + {description} + + ) : null + } + > + + + + + + + { + field.onChange(date?.toISOString()) + }} + initialFocus + /> + + + + + )} + /> + + + ) case 'string': return ( - - ) : null - } - descriptionText={ - properties.description ? ( - - ) : null - } - actions={ - !!properties.isSecret ? ( -