fix: missing checkbox

This commit is contained in:
SevicheCC 2023-06-05 17:22:15 +08:00
parent b541573d77
commit f2ca97238b
Signed by: SevicheCC
GPG key ID: C577000000000000
3 changed files with 17 additions and 8 deletions

View file

@ -33,6 +33,7 @@ export type MethodType =
| "push"; | "push";
export interface ScopeInfo { export interface ScopeInfo {
method: MethodType; method: MethodType;
label: string;
scopes?: string[] | string[][]; scopes?: string[] | string[][];
description: string; description: string;
} }
@ -40,29 +41,35 @@ export interface ScopeInfo {
const scopesInfo: ScopeInfo[] = [ const scopesInfo: ScopeInfo[] = [
{ {
method: "read", method: "read",
label: 'Read',
scopes: READ_SCOPES, scopes: READ_SCOPES,
description: "read account's data", description: "read account's data",
}, },
{ {
method: "write", method: "write",
label: 'Write',
scopes: WRITE_SCOPES, scopes: WRITE_SCOPES,
description: "modify account's data", description: "modify account's data",
}, },
{ {
method: "follow", method: "follow",
label: 'Follow',
description: "modify account relationships,deprecated in 3.5.0 and newer.", description: "modify account relationships,deprecated in 3.5.0 and newer.",
}, },
{ {
method: "push", method: "push",
label: "Push",
description: "receive push notifications", description: "receive push notifications",
}, },
{ {
method: "admin", method: "admin",
label: 'Admin',
scopes: [ADMIN_READ_SCOPES, ADMIN_WRITE_SCOPES], scopes: [ADMIN_READ_SCOPES, ADMIN_WRITE_SCOPES],
description: "read all data on the server", description: "read all data on the server",
}, },
{ {
method: "crypto", method: "crypto",
label: "Crypto",
description: "use end-to-end encryption", description: "use end-to-end encryption",
}, },
]; ];

View file

@ -1,12 +1,14 @@
import { Checkbox } from "@radix-ui/react-checkbox"; 'use client'
import { MethodType } from "./InputForm"; import { MethodType } from "./InputForm";
import { Checkbox } from "@/components/ui/checkbox";
interface ScopeCheckboxProps { interface ScopeCheckboxProps {
scope: string; scope: string;
method: MethodType; method: MethodType;
} }
const ScopeCheckbox: React.FC<ScopeCheckboxProps> = ({ scope, method }) => { const ScopeItem: React.FC<ScopeCheckboxProps> = ({ scope, method }) => {
return ( return (
<div className={`items-top flex space-x-2 hover:cursor-pointer`}> <div className={`items-top flex space-x-2 hover:cursor-pointer`}>
<Checkbox id={`${scope}`} /> <Checkbox id={`${scope}`} />
@ -25,4 +27,4 @@ const ScopeCheckbox: React.FC<ScopeCheckboxProps> = ({ scope, method }) => {
); );
}; };
export default ScopeCheckbox; export default ScopeItem;

View file

@ -10,14 +10,14 @@ import { Button } from "@/components/ui/button";
import { ChevronsUpDown } from "lucide-react"; import { ChevronsUpDown } from "lucide-react";
import { ScopeInfo } from "./InputForm"; import { ScopeInfo } from "./InputForm";
import ScopeCheckbox from "./ScopeCheckbox"; import ScopeItem from "./ScopeItem";
interface ScopeSectionProps { interface ScopeSectionProps {
info: ScopeInfo; info: ScopeInfo;
field: any; field: any;
} }
const ScopeSection: React.FC<ScopeSectionProps> = ({ info, field }) => { const ScopeSection: React.FC<ScopeSectionProps> = ({ info, field }) => {
const { method, description, scopes } = info; const { method, description, scopes, label } = info;
return ( return (
<Collapsible className="flex flex-col rounded-md bg-slate-50 px-4 py-3"> <Collapsible className="flex flex-col rounded-md bg-slate-50 px-4 py-3">
@ -29,7 +29,7 @@ const ScopeSection: React.FC<ScopeSectionProps> = ({ info, field }) => {
htmlFor={method} htmlFor={method}
className="text-sm font-medium leading-none hover:cursor-pointer peer-disabled:cursor-not-allowed peer-disabled:opacity-70" className="text-sm font-medium leading-none hover:cursor-pointer peer-disabled:cursor-not-allowed peer-disabled:opacity-70"
> >
{method} {label}
</label> </label>
<p className="text-xs text-muted-foreground">{description}</p> <p className="text-xs text-muted-foreground">{description}</p>
</div> </div>
@ -57,12 +57,12 @@ const ScopeSection: React.FC<ScopeSectionProps> = ({ info, field }) => {
className="flex flex-col gap-2" className="flex flex-col gap-2"
> >
{items.map((item) => ( {items.map((item) => (
<ScopeCheckbox scope={item} key={item} method={method} /> <ScopeItem scope={item} key={item} method={method} />
))} ))}
</div> </div>
)) ))
: (scopes as string[]).map((scope) => ( : (scopes as string[]).map((scope) => (
<ScopeCheckbox scope={scope} key={scope} method={method} /> <ScopeItem scope={scope} key={scope} method={method} />
))} ))}
</div> </div>
</CollapsibleContent> </CollapsibleContent>