v2: fixed oauth errors, oauth clients native control added
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
"use client"
|
||||
|
||||
import { useTranslations } from "next-intl";
|
||||
import type { OAuthClient } from "@/types";
|
||||
import { useState } from "react";
|
||||
import { DataTable } from "./table";
|
||||
import { useColumns } from "./columns";
|
||||
import { CreateClientDialog } from "./createClientDialog";
|
||||
import { UpdateClientDialog } from "./updateClientDialog";
|
||||
|
||||
interface Props {
|
||||
clientsData: OAuthClient[];
|
||||
}
|
||||
|
||||
export default function Applications({ clientsData }: Props) {
|
||||
const t = useTranslations("MePage.items.applications");
|
||||
const [editingClient, setEditingClient] = useState<OAuthClient | null>(null);
|
||||
const [clients, setClients] = useState<OAuthClient[] | []>(clientsData);
|
||||
const columns = useColumns({ setClients, setEditingClient });
|
||||
|
||||
return (
|
||||
<div className="w-full lg:max-w-2xl flex flex-col gap-8">
|
||||
<div className="lg:max-w-sm space-y-2">
|
||||
<h1 className="text-xl">{t("title")}</h1>
|
||||
<p className="text-sm text-muted-foreground">{t("subtitle")}</p>
|
||||
</div>
|
||||
<CreateClientDialog setClients={setClients} />
|
||||
<UpdateClientDialog client={editingClient} onClose={() => setEditingClient(null)} setClients={setClients} />
|
||||
<div className="space-y-4">
|
||||
{clients.length > 0 ? <DataTable columns={columns} data={clients || []} /> : <h2 className="text-muted-foreground text-lg">{t("noApplications")}</h2>}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,94 @@
|
||||
"use client"
|
||||
|
||||
import { createColumnHelper } from "@tanstack/react-table";
|
||||
import { Dispatch, SetStateAction, useMemo } from "react";
|
||||
import { type DataTableFeatures } from "./features";
|
||||
import { OAuthClient } from "@/types";
|
||||
import { Badge } from "@/components/ui/badge";
|
||||
import { useTranslations } from "next-intl";
|
||||
import { BanIcon, MoreHorizontal, PencilIcon } from "lucide-react";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger } from "@/components/ui/dropdown-menu";
|
||||
import { deleteClient } from "@/actions/clients";
|
||||
|
||||
const columnHelper = createColumnHelper<DataTableFeatures, OAuthClient>();
|
||||
|
||||
async function handleDisable({ id, setClients }: { id: string; setClients: Dispatch<SetStateAction<OAuthClient[] | []>> }) {
|
||||
try {
|
||||
await deleteClient(id);
|
||||
setClients((prev) => prev ? prev.map((c) => c.id === id ? { ...c, is_active: false } : c) : prev);
|
||||
} catch {}
|
||||
}
|
||||
|
||||
export function useColumns({ setClients, setEditingClient }: { setClients: Dispatch<SetStateAction<OAuthClient[] | []>>; setEditingClient: Dispatch<SetStateAction<OAuthClient | null>>; }) {
|
||||
const t = useTranslations("MePage.items.applications.table");
|
||||
|
||||
return useMemo(
|
||||
() =>
|
||||
columnHelper.columns([
|
||||
columnHelper.accessor("name", {
|
||||
header: t("client"),
|
||||
cell: ({ row }) => (
|
||||
<div className="flex flex-col gap-0.5">
|
||||
<h4>{row.getValue("name")}</h4>
|
||||
<h5 className="text-xs text-muted-foreground">
|
||||
{row.original.client_id}
|
||||
</h5>
|
||||
</div>
|
||||
),
|
||||
}),
|
||||
columnHelper.accessor("redirect_uris", {
|
||||
header: t("redirectURIs"),
|
||||
cell: ({ row }) => (
|
||||
<div className="flex flex-row gap-1 flex-wrap">
|
||||
{(row.getValue("redirect_uris") as string[]).map((url) => (
|
||||
<Badge key={url} variant="secondary">
|
||||
{url}
|
||||
</Badge>
|
||||
))}
|
||||
</div>
|
||||
),
|
||||
}),
|
||||
columnHelper.accessor("scopes", {
|
||||
header: t("scopes"),
|
||||
cell: ({ row }) => (
|
||||
<div className="flex flex-row gap-1 flex-wrap">
|
||||
{(row.getValue("scopes") as string[]).map((scope) => (
|
||||
<Badge key={scope} variant="secondary">
|
||||
{scope}
|
||||
</Badge>
|
||||
))}
|
||||
</div>
|
||||
),
|
||||
}),
|
||||
columnHelper.accessor("is_active", {
|
||||
header: t("status"),
|
||||
cell: ({ row }) => {
|
||||
return row.getValue("is_active") === true ? t("active") : t("disabled")
|
||||
},
|
||||
}),
|
||||
|
||||
columnHelper.display({
|
||||
id: "actions",
|
||||
cell: ({ row }) => {
|
||||
const client = row.original;
|
||||
|
||||
return (
|
||||
<DropdownMenu>
|
||||
<DropdownMenuTrigger asChild>
|
||||
<Button variant="ghost" className="h-8 w-8 p-0">
|
||||
<MoreHorizontal className="h-4 w-4" />
|
||||
</Button>
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent align="end">
|
||||
<DropdownMenuItem onClick={() => setEditingClient(client)}><PencilIcon />{t("edit")}</DropdownMenuItem>
|
||||
{client.is_active && <DropdownMenuItem onClick={() => handleDisable({ id: client.id, setClients })}><BanIcon />{t("disable")}</DropdownMenuItem>}
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
)
|
||||
},
|
||||
}),
|
||||
]),
|
||||
[t, setClients, setEditingClient]
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,256 @@
|
||||
"use client"
|
||||
|
||||
import { Button } from "@/components/ui/button";
|
||||
import {
|
||||
Dialog,
|
||||
DialogContent,
|
||||
DialogDescription,
|
||||
DialogFooter,
|
||||
DialogHeader,
|
||||
DialogTitle,
|
||||
DialogTrigger,
|
||||
} from "@/components/ui/dialog";
|
||||
import { Checkbox } from "@/components/ui/checkbox";
|
||||
import { Field, FieldError, FieldGroup, FieldLabel, FieldDescription } from "@/components/ui/field";
|
||||
import { Input } from "@/components/ui/input";
|
||||
import { Spinner } from "@/components/ui/spinner";
|
||||
import { useTranslations } from "next-intl";
|
||||
import { Dispatch, SetStateAction, useState } from "react";
|
||||
import { useFieldArray, useForm, Controller, SubmitHandler } from "react-hook-form";
|
||||
import { Plus, Trash2, Copy, Check } from "lucide-react";
|
||||
import { createClient } from "@/actions/clients";
|
||||
import type { CreatedOAuthClient, OAuthClient } from "@/types";
|
||||
|
||||
interface FormData {
|
||||
name: string;
|
||||
redirect_uris: { value: string }[];
|
||||
scopes: string[];
|
||||
}
|
||||
|
||||
interface Props {
|
||||
setClients: Dispatch<SetStateAction<OAuthClient[] | []>>;
|
||||
}
|
||||
|
||||
const GRANT_TYPES = ["authorization_code", "refresh_token"] as const;
|
||||
const SCOPES = ["profile:read", "profile:edit"] as const;
|
||||
|
||||
export function CreateClientDialog({ setClients }: Props) {
|
||||
const t = useTranslations("MePage.items.applications.dialog");
|
||||
const [isOpen, setIsOpen] = useState(false);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
const [createdClient, setCreatedClient] = useState<CreatedOAuthClient | null>(null);
|
||||
const [copied, setCopied] = useState<"id" | "secret" | null>(null);
|
||||
|
||||
const { register, handleSubmit, control, reset, formState: { errors, isSubmitting } } = useForm<FormData>({
|
||||
defaultValues: {
|
||||
name: "",
|
||||
redirect_uris: [{ value: "" }],
|
||||
scopes: [],
|
||||
},
|
||||
});
|
||||
|
||||
const { fields, append, remove } = useFieldArray({
|
||||
control,
|
||||
name: "redirect_uris",
|
||||
});
|
||||
|
||||
const onSubmit: SubmitHandler<FormData> = async (data) => {
|
||||
setError(null);
|
||||
|
||||
const result = await createClient({
|
||||
name: data.name,
|
||||
redirect_uris: data.redirect_uris.map((r) => r.value).filter(Boolean),
|
||||
grant_types: [...GRANT_TYPES],
|
||||
scopes: data.scopes,
|
||||
});
|
||||
|
||||
if (!result.success || !result.client) {
|
||||
setError(result.message ?? null);
|
||||
return;
|
||||
}
|
||||
|
||||
setClients((prev) => (prev ? [...prev, result.client!] : [result.client!]));
|
||||
setCreatedClient(result.client);
|
||||
};
|
||||
|
||||
const handleCopy = async (value: string, key: "id" | "secret") => {
|
||||
await navigator.clipboard.writeText(value);
|
||||
setCopied(key);
|
||||
setTimeout(() => setCopied(null), 2000);
|
||||
};
|
||||
|
||||
const handleClose = (open: boolean) => {
|
||||
setIsOpen(open);
|
||||
if (!open) {
|
||||
reset();
|
||||
setCreatedClient(null);
|
||||
setError(null);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<Dialog open={isOpen} onOpenChange={handleClose}>
|
||||
<DialogTrigger asChild>
|
||||
<Button className="w-max">{t("trigger")}</Button>
|
||||
</DialogTrigger>
|
||||
<DialogContent onInteractOutside={(e) => createdClient && e.preventDefault()}>
|
||||
{!createdClient ? (
|
||||
<>
|
||||
<DialogHeader>
|
||||
<DialogTitle>{t("title")}</DialogTitle>
|
||||
<DialogDescription>{t("subtitle")}</DialogDescription>
|
||||
</DialogHeader>
|
||||
<form onSubmit={handleSubmit(onSubmit)}>
|
||||
<FieldGroup>
|
||||
<Field data-invalid={!!errors.name}>
|
||||
<FieldLabel htmlFor="name">{t("name.title")}</FieldLabel>
|
||||
<Input
|
||||
id="name"
|
||||
disabled={isSubmitting}
|
||||
aria-invalid={!!errors.name}
|
||||
{...register("name", {
|
||||
required: t("required"),
|
||||
minLength: { value: 2, message: t("name.minLength") },
|
||||
maxLength: { value: 128, message: t("name.maxLength") },
|
||||
})}
|
||||
/>
|
||||
{errors.name && <FieldError>{errors.name.message}</FieldError>}
|
||||
</Field>
|
||||
|
||||
<Field>
|
||||
<FieldLabel>{t("redirectUris.title")}</FieldLabel>
|
||||
<div className="flex flex-col gap-2">
|
||||
{fields.map((field, index) => (
|
||||
<div key={field.id} className="flex gap-2">
|
||||
<Input
|
||||
disabled={isSubmitting}
|
||||
placeholder={t("redirectUris.placeholder")}
|
||||
{...register(`redirect_uris.${index}.value` as const, {
|
||||
required: index === 0 ? t("required") : false,
|
||||
pattern: {
|
||||
value: /^https?:\/\/.+/,
|
||||
message: t("redirectUris.invalid"),
|
||||
},
|
||||
})}
|
||||
/>
|
||||
<Button
|
||||
type="button"
|
||||
variant="outline"
|
||||
size="icon"
|
||||
disabled={isSubmitting || fields.length === 1}
|
||||
onClick={() => remove(index)}
|
||||
>
|
||||
<Trash2 />
|
||||
</Button>
|
||||
</div>
|
||||
))}
|
||||
{errors.redirect_uris?.[0]?.value && (
|
||||
<FieldError>{errors.redirect_uris[0]?.value?.message}</FieldError>
|
||||
)}
|
||||
<Button
|
||||
type="button"
|
||||
variant="outline"
|
||||
size="sm"
|
||||
disabled={isSubmitting}
|
||||
onClick={() => append({ value: "" })}
|
||||
>
|
||||
<Plus />
|
||||
{t("redirectUris.add")}
|
||||
</Button>
|
||||
</div>
|
||||
</Field>
|
||||
|
||||
<Field data-invalid={!!errors.scopes}>
|
||||
<FieldLabel>{t("scopes.title")}</FieldLabel>
|
||||
<Controller
|
||||
name="scopes"
|
||||
control={control}
|
||||
rules={{ required: t("required") }}
|
||||
render={({ field }) => (
|
||||
<div className="flex flex-col gap-2">
|
||||
{SCOPES.map((scope) => (
|
||||
<label key={scope} className="flex items-center gap-2 text-sm">
|
||||
<Checkbox
|
||||
disabled={isSubmitting}
|
||||
checked={field.value.includes(scope)}
|
||||
onCheckedChange={(checked) => {
|
||||
field.onChange(
|
||||
checked
|
||||
? [...field.value, scope]
|
||||
: field.value.filter((s) => s !== scope)
|
||||
);
|
||||
}}
|
||||
/>
|
||||
{t(`scopes.${scope}`)}
|
||||
</label>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
/>
|
||||
{errors.scopes && <FieldError>{errors.scopes.message}</FieldError>}
|
||||
</Field>
|
||||
|
||||
{error && <FieldError className="text-center">{error}</FieldError>}
|
||||
</FieldGroup>
|
||||
|
||||
<DialogFooter className="mt-6">
|
||||
<Button type="submit" disabled={isSubmitting}>
|
||||
{isSubmitting && <Spinner />}
|
||||
{t("submit")}
|
||||
</Button>
|
||||
</DialogFooter>
|
||||
</form>
|
||||
</>
|
||||
) : (
|
||||
<>
|
||||
<DialogHeader>
|
||||
<DialogTitle>{t("secretReveal.title")}</DialogTitle>
|
||||
<DialogDescription>{t("secretReveal.subtitle")}</DialogDescription>
|
||||
</DialogHeader>
|
||||
|
||||
<FieldGroup>
|
||||
<Field>
|
||||
<FieldLabel>{t("secretReveal.clientId")}</FieldLabel>
|
||||
<div className="flex gap-2">
|
||||
<Input readOnly value={createdClient.client_id} className="font-mono text-sm" />
|
||||
<Button
|
||||
type="button"
|
||||
variant="outline"
|
||||
size="icon"
|
||||
onClick={() => handleCopy(createdClient.client_id, "id")}
|
||||
>
|
||||
{copied === "id" ? <Check /> : <Copy />}
|
||||
</Button>
|
||||
</div>
|
||||
</Field>
|
||||
|
||||
<Field>
|
||||
<FieldLabel>{t("secretReveal.clientSecret")}</FieldLabel>
|
||||
<div className="flex gap-2">
|
||||
<Input readOnly value={createdClient.client_secret} className="font-mono text-sm" />
|
||||
<Button
|
||||
type="button"
|
||||
variant="outline"
|
||||
size="icon"
|
||||
onClick={() => handleCopy(createdClient.client_secret, "secret")}
|
||||
>
|
||||
{copied === "secret" ? <Check /> : <Copy />}
|
||||
</Button>
|
||||
</div>
|
||||
<FieldDescription className="text-destructive">
|
||||
{t("secretReveal.warning")}
|
||||
</FieldDescription>
|
||||
</Field>
|
||||
</FieldGroup>
|
||||
|
||||
<DialogFooter className="mt-6">
|
||||
<Button onClick={() => handleClose(false)}>
|
||||
{t("secretReveal.confirm")}
|
||||
</Button>
|
||||
</DialogFooter>
|
||||
</>
|
||||
)}
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
import {
|
||||
columnFilteringFeature,
|
||||
columnVisibilityFeature,
|
||||
createFilteredRowModel,
|
||||
createPaginatedRowModel,
|
||||
createSortedRowModel,
|
||||
filterFn_includesString,
|
||||
rowPaginationFeature,
|
||||
rowSelectionFeature,
|
||||
rowSortingFeature,
|
||||
sortFn_alphanumeric,
|
||||
sortFn_text,
|
||||
tableFeatures,
|
||||
} from "@tanstack/react-table";
|
||||
|
||||
export const features = tableFeatures({
|
||||
columnFilteringFeature,
|
||||
columnVisibilityFeature,
|
||||
rowPaginationFeature,
|
||||
rowSelectionFeature,
|
||||
rowSortingFeature,
|
||||
filteredRowModel: createFilteredRowModel(),
|
||||
paginatedRowModel: createPaginatedRowModel(),
|
||||
sortedRowModel: createSortedRowModel(),
|
||||
filterFns: { includesString: filterFn_includesString },
|
||||
sortFns: { alphanumeric: sortFn_alphanumeric, text: sortFn_text },
|
||||
});
|
||||
|
||||
export type DataTableFeatures = typeof features;
|
||||
@@ -0,0 +1,49 @@
|
||||
"use client"
|
||||
|
||||
import { useTable, type ColumnDef, type RowData } from "@tanstack/react-table";
|
||||
import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from "@/components/ui/table";
|
||||
import { features, type DataTableFeatures } from "./features";
|
||||
|
||||
interface DataTableProps<TData extends RowData> {
|
||||
columns: ColumnDef<DataTableFeatures, TData>[];
|
||||
data: TData[];
|
||||
}
|
||||
|
||||
export function DataTable<TData extends RowData>({ columns, data }: DataTableProps<TData>) {
|
||||
const table = useTable({ features, data, columns });
|
||||
|
||||
return (
|
||||
<div className="overflow-hidden rounded-md border">
|
||||
<Table>
|
||||
<TableHeader>
|
||||
{table.getHeaderGroups().map((headerGroup) => (
|
||||
<TableRow key={headerGroup.id}>
|
||||
{headerGroup.headers.map((header) => {
|
||||
return (
|
||||
<TableHead key={header.id}>
|
||||
{header.isPlaceholder ? null : (
|
||||
<table.FlexRender header={header} />
|
||||
)}
|
||||
</TableHead>
|
||||
)
|
||||
})}
|
||||
</TableRow>
|
||||
))}
|
||||
</TableHeader>
|
||||
<TableBody>
|
||||
{table.getRowModel().rows?.length > 0 && (
|
||||
table.getRowModel().rows.map((row) => (
|
||||
<TableRow key={row.id} data-state={row.getIsSelected() && "selected"}>
|
||||
{row.getVisibleCells().map((cell) => (
|
||||
<TableCell key={cell.id}>
|
||||
<table.FlexRender cell={cell} />
|
||||
</TableCell>
|
||||
))}
|
||||
</TableRow>
|
||||
))
|
||||
)}
|
||||
</TableBody>
|
||||
</Table>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,186 @@
|
||||
"use client"
|
||||
|
||||
import { Dispatch, SetStateAction, useEffect, useState } from "react";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import {
|
||||
Dialog,
|
||||
DialogContent,
|
||||
DialogDescription,
|
||||
DialogFooter,
|
||||
DialogHeader,
|
||||
DialogTitle,
|
||||
} from "@/components/ui/dialog";
|
||||
import { Checkbox } from "@/components/ui/checkbox";
|
||||
import { Field, FieldError, FieldGroup, FieldLabel } from "@/components/ui/field";
|
||||
import { Input } from "@/components/ui/input";
|
||||
import { Spinner } from "@/components/ui/spinner";
|
||||
import { useTranslations } from "next-intl";
|
||||
import { useFieldArray, useForm, Controller, SubmitHandler } from "react-hook-form";
|
||||
import { Plus, Trash2 } from "lucide-react";
|
||||
import { updateClient } from "@/actions/clients";
|
||||
import type { OAuthClient } from "@/types";
|
||||
|
||||
interface FormData {
|
||||
name: string;
|
||||
redirect_uris: { value: string }[];
|
||||
scopes: string[];
|
||||
}
|
||||
|
||||
interface Props {
|
||||
client: OAuthClient | null;
|
||||
onClose: () => void;
|
||||
setClients: Dispatch<SetStateAction<OAuthClient[] | []>>;
|
||||
}
|
||||
|
||||
const SCOPES = ["profile:read", "profile:edit"] as const;
|
||||
|
||||
export function UpdateClientDialog({ client, onClose, setClients }: Props) {
|
||||
const t = useTranslations("MePage.items.applications.dialog");
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
|
||||
const { register, handleSubmit, control, reset, formState: { errors, isSubmitting }} = useForm<FormData>({
|
||||
defaultValues: { name: "", redirect_uris: [{ value: "" }], scopes: [] },
|
||||
});
|
||||
|
||||
const { fields, append, remove } = useFieldArray({
|
||||
control,
|
||||
name: "redirect_uris",
|
||||
});
|
||||
|
||||
useEffect(() => {
|
||||
if (client) {
|
||||
reset({
|
||||
name: client.name,
|
||||
redirect_uris: client.redirect_uris.map((value) => ({ value })),
|
||||
scopes: client.scopes,
|
||||
});
|
||||
}
|
||||
}, [client, reset]);
|
||||
|
||||
const onSubmit: SubmitHandler<FormData> = async (data) => {
|
||||
if (!client) return;
|
||||
setError(null);
|
||||
|
||||
const result = await updateClient(client.id, {
|
||||
name: data.name,
|
||||
redirect_uris: data.redirect_uris.map((r) => r.value).filter(Boolean),
|
||||
scopes: data.scopes,
|
||||
});
|
||||
|
||||
if (!result.success || !result.client) {
|
||||
setError(result.message ?? null);
|
||||
return;
|
||||
}
|
||||
|
||||
setClients((prev) =>
|
||||
prev ? prev.map((c) => (c.id === result.client!.id ? result.client! : c)) : prev
|
||||
);
|
||||
onClose();
|
||||
};
|
||||
|
||||
return (
|
||||
<Dialog open={!!client} onOpenChange={(open) => !open && onClose()}>
|
||||
<DialogContent>
|
||||
<DialogHeader>
|
||||
<DialogTitle>{t("editTitle")}</DialogTitle>
|
||||
<DialogDescription>{t("editSubtitle")}</DialogDescription>
|
||||
</DialogHeader>
|
||||
<form onSubmit={handleSubmit(onSubmit)}>
|
||||
<FieldGroup>
|
||||
<Field data-invalid={!!errors.name}>
|
||||
<FieldLabel htmlFor="name">{t("name.title")}</FieldLabel>
|
||||
<Input
|
||||
id="name"
|
||||
disabled={isSubmitting}
|
||||
aria-invalid={!!errors.name}
|
||||
{...register("name", {
|
||||
required: t("required"),
|
||||
minLength: { value: 2, message: t("name.minLength") },
|
||||
maxLength: { value: 128, message: t("name.maxLength") },
|
||||
})}
|
||||
/>
|
||||
{errors.name && <FieldError>{errors.name.message}</FieldError>}
|
||||
</Field>
|
||||
|
||||
<Field>
|
||||
<FieldLabel>{t("redirectUris.title")}</FieldLabel>
|
||||
<div className="flex flex-col gap-2">
|
||||
{fields.map((field, index) => (
|
||||
<div key={field.id} className="flex gap-2">
|
||||
<Input
|
||||
disabled={isSubmitting}
|
||||
placeholder={t("redirectUris.placeholder")}
|
||||
{...register(`redirect_uris.${index}.value` as const, {
|
||||
required: index === 0 ? t("required") : false,
|
||||
pattern: { value: /^https?:\/\/.+/, message: t("redirectUris.invalid") },
|
||||
})}
|
||||
/>
|
||||
<Button
|
||||
type="button"
|
||||
variant="outline"
|
||||
size="icon"
|
||||
disabled={isSubmitting || fields.length === 1}
|
||||
onClick={() => remove(index)}
|
||||
>
|
||||
<Trash2 />
|
||||
</Button>
|
||||
</div>
|
||||
))}
|
||||
{errors.redirect_uris?.[0]?.value && (
|
||||
<FieldError>{errors.redirect_uris[0]?.value?.message}</FieldError>
|
||||
)}
|
||||
<Button
|
||||
type="button"
|
||||
variant="outline"
|
||||
size="sm"
|
||||
disabled={isSubmitting}
|
||||
onClick={() => append({ value: "" })}
|
||||
>
|
||||
<Plus />
|
||||
{t("redirectUris.add")}
|
||||
</Button>
|
||||
</div>
|
||||
</Field>
|
||||
|
||||
<Field data-invalid={!!errors.scopes}>
|
||||
<FieldLabel>{t("scopes.title")}</FieldLabel>
|
||||
<Controller
|
||||
name="scopes"
|
||||
control={control}
|
||||
rules={{ required: t("required") }}
|
||||
render={({ field }) => (
|
||||
<div className="flex flex-col gap-2">
|
||||
{SCOPES.map((scope) => (
|
||||
<label key={scope} className="flex items-center gap-2 text-sm">
|
||||
<Checkbox
|
||||
disabled={isSubmitting}
|
||||
checked={field.value.includes(scope)}
|
||||
onCheckedChange={(checked) => {
|
||||
field.onChange(
|
||||
checked ? [...field.value, scope] : field.value.filter((s) => s !== scope)
|
||||
);
|
||||
}}
|
||||
/>
|
||||
{t(`scopes.${scope}`)}
|
||||
</label>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
/>
|
||||
{errors.scopes && <FieldError>{errors.scopes.message}</FieldError>}
|
||||
</Field>
|
||||
|
||||
{error && <FieldError className="text-center">{error}</FieldError>}
|
||||
</FieldGroup>
|
||||
|
||||
<DialogFooter className="mt-6">
|
||||
<Button type="submit" disabled={isSubmitting}>
|
||||
{isSubmitting && <Spinner />}
|
||||
{t("editSubmit")}
|
||||
</Button>
|
||||
</DialogFooter>
|
||||
</form>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user