mirror of
https://github.com/supabase/supabase.git
synced 2026-12-04 15:39:13 +00:00
## Context This is largely just a mechanical change here: Opting to use lucide icons with the `Icon` suffix across all icon imports within `studio` - so that it’s clearer which components are icons + reduces the possibility of name collision with our own components - e.g <User /> vs <UserIcon /> Also added a eslint rule for this: <img width="1069" height="167" alt="image" src="https://github.com/user-attachments/assets/7f36f443-5ca2-4bf6-8d22-86e774513bfc" /> And updated `AGENTS.md` as such: ``` Icons come from `lucide-react`, always imported with the `Icon` suffix (`import { CheckIcon, Trash2Icon } from 'lucide-react'`) — never the bare names (`Check`) or `Check as CheckIcon` aliases (lint-enforced). ```
129 lines
3.7 KiB
TypeScript
129 lines
3.7 KiB
TypeScript
import { UploadIcon } from 'lucide-react'
|
|
import { useEffect, useRef, useState } from 'react'
|
|
import { useForm } from 'react-hook-form'
|
|
import {
|
|
Button,
|
|
FormControl,
|
|
FormField,
|
|
FormItem,
|
|
FormMessage,
|
|
Input,
|
|
Tabs,
|
|
TabsContent,
|
|
TabsList,
|
|
TabsTrigger,
|
|
} from 'ui'
|
|
import { FormItemLayout } from 'ui-patterns/form/FormItemLayout/FormItemLayout'
|
|
|
|
import { SSOConfigFormSchema } from './SSOConfig'
|
|
|
|
export const SSOMetadata = ({
|
|
form,
|
|
}: {
|
|
form: ReturnType<typeof useForm<SSOConfigFormSchema>>
|
|
}) => {
|
|
const fileInputRef = useRef<HTMLInputElement>(null)
|
|
const [fileName, setFileName] = useState<string | null>(null)
|
|
const [tab, setTab] = useState<'url' | 'file'>('url')
|
|
|
|
useEffect(() => {
|
|
if (form.getValues('metadataXmlFile')) {
|
|
setTab('file')
|
|
} else if (form.getValues('metadataXmlUrl')) {
|
|
setTab('url')
|
|
}
|
|
}, [form])
|
|
|
|
const handleFileChange = async (e: React.ChangeEvent<HTMLInputElement>) => {
|
|
form.clearErrors('metadataXmlFile')
|
|
const file = e.target.files?.[0]
|
|
if (!file) return
|
|
if (!file.name.endsWith('.xml')) {
|
|
form.setError('metadataXmlFile', {
|
|
type: 'manual',
|
|
message: 'Please upload a valid .xml file',
|
|
})
|
|
return
|
|
}
|
|
try {
|
|
const text = await file.text()
|
|
form.setValue('metadataXmlFile', text, { shouldDirty: true })
|
|
setFileName(file.name)
|
|
} catch (err) {
|
|
form.setError('metadataXmlFile', {
|
|
type: 'manual',
|
|
message: 'Failed to read file',
|
|
})
|
|
}
|
|
}
|
|
|
|
return (
|
|
<FormItemLayout
|
|
label="Metadata"
|
|
layout="flex-row-reverse"
|
|
description="Provide a link to your metadata .xml file or upload one."
|
|
className="gap-1"
|
|
>
|
|
<div className=" w-96">
|
|
<Tabs
|
|
value={tab}
|
|
onValueChange={(value: string) => setTab(value as 'url' | 'file')}
|
|
className="max-w-2xl"
|
|
>
|
|
<TabsList className="mx-auto gap-5 w-auto">
|
|
<TabsTrigger className=" " value="url">
|
|
URL
|
|
</TabsTrigger>
|
|
<TabsTrigger className=" " value="file">
|
|
Upload file
|
|
</TabsTrigger>
|
|
</TabsList>
|
|
<TabsContent value="url">
|
|
<FormField
|
|
name="metadataXmlUrl"
|
|
render={({ field }) => (
|
|
<FormItem>
|
|
<FormControl>
|
|
<Input
|
|
{...field}
|
|
placeholder="https://example.com/metadata.xml"
|
|
autoComplete="off"
|
|
/>
|
|
</FormControl>
|
|
<FormMessage />
|
|
</FormItem>
|
|
)}
|
|
/>
|
|
</TabsContent>
|
|
<TabsContent value="file">
|
|
<FormField
|
|
name="metadataXmlUrl"
|
|
render={() => (
|
|
<div className="flex flex-col gap-2 max-w-md">
|
|
<div className="flex items-center gap-2">
|
|
<input
|
|
ref={fileInputRef}
|
|
type="file"
|
|
accept=".xml"
|
|
className="hidden"
|
|
onChange={handleFileChange}
|
|
/>
|
|
<Button
|
|
icon={<UploadIcon className="w-4 h-4" />}
|
|
onClick={() => fileInputRef.current?.click()}
|
|
>
|
|
Upload XML
|
|
</Button>
|
|
{fileName && <span className="text-xs text-foreground-light">{fileName}</span>}
|
|
</div>
|
|
<FormMessage />
|
|
</div>
|
|
)}
|
|
/>
|
|
</TabsContent>
|
|
</Tabs>
|
|
</div>
|
|
</FormItemLayout>
|
|
)
|
|
}
|