mirror of
https://github.com/Sevichecc/m-oauth.git
synced 2025-04-30 06:59:29 +08:00
feat: select all scopes
This commit is contained in:
parent
2f34f8fc50
commit
ea8b50ee46
3 changed files with 26 additions and 20 deletions
|
@ -41,19 +41,25 @@ export interface ScopeInfo {
|
||||||
const scopesInfo: ScopeInfo[] = [
|
const scopesInfo: ScopeInfo[] = [
|
||||||
{
|
{
|
||||||
method: "read",
|
method: "read",
|
||||||
label: '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',
|
label: "Write",
|
||||||
scopes: WRITE_SCOPES,
|
scopes: WRITE_SCOPES,
|
||||||
description: "modify account's data",
|
description: "modify account's data",
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
method: "admin",
|
||||||
|
label: "Admin",
|
||||||
|
scopes: [ADMIN_READ_SCOPES, ADMIN_WRITE_SCOPES],
|
||||||
|
description: "read all data on the server",
|
||||||
|
},
|
||||||
{
|
{
|
||||||
method: "follow",
|
method: "follow",
|
||||||
label: '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.",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -61,12 +67,7 @@ const scopesInfo: ScopeInfo[] = [
|
||||||
label: "Push",
|
label: "Push",
|
||||||
description: "receive push notifications",
|
description: "receive push notifications",
|
||||||
},
|
},
|
||||||
{
|
|
||||||
method: "admin",
|
|
||||||
label: 'Admin',
|
|
||||||
scopes: [ADMIN_READ_SCOPES, ADMIN_WRITE_SCOPES],
|
|
||||||
description: "read all data on the server",
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
method: "crypto",
|
method: "crypto",
|
||||||
label: "Crypto",
|
label: "Crypto",
|
||||||
|
@ -77,9 +78,9 @@ const scopesInfo: ScopeInfo[] = [
|
||||||
const formSchema = z.object({
|
const formSchema = z.object({
|
||||||
instance: z.string().trim(),
|
instance: z.string().trim(),
|
||||||
clientName: z.string().trim(),
|
clientName: z.string().trim(),
|
||||||
redirectUris: z.string().url().trim(),
|
redirectUris: z.string().trim(),
|
||||||
scopes: z.string().array().nonempty().optional(),
|
scopes: z.string().array().nonempty().optional(),
|
||||||
website: z.string().trim().optional(),
|
website: z.string().url().trim().optional(),
|
||||||
});
|
});
|
||||||
|
|
||||||
const InputForm = () => {
|
const InputForm = () => {
|
||||||
|
@ -89,12 +90,13 @@ const InputForm = () => {
|
||||||
instance: "https://",
|
instance: "https://",
|
||||||
clientName: "",
|
clientName: "",
|
||||||
redirectUris: "",
|
redirectUris: "",
|
||||||
scopes:[]
|
scopes: [],
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
function onSubmit(values: z.infer<typeof formSchema>) {
|
function onSubmit(values: z.infer<typeof formSchema>) {
|
||||||
console.log(values);
|
const scopes = values.scopes?.join(" ");
|
||||||
|
console.log(scopes);
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|
|
@ -10,25 +10,30 @@ interface ScopeCheckboxProps {
|
||||||
}
|
}
|
||||||
|
|
||||||
const ScopeItem: React.FC<ScopeCheckboxProps> = ({ scope, method, field }) => {
|
const ScopeItem: React.FC<ScopeCheckboxProps> = ({ scope, method, field }) => {
|
||||||
|
const isCovered = field.value?.includes(method);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={`items-top flex space-x-2 hover:cursor-pointer`}>
|
<div className="items-top 'hover:cursor-pointer flex space-x-2 hover:cursor-pointer">
|
||||||
<Checkbox
|
<Checkbox
|
||||||
|
disabled={isCovered}
|
||||||
id={scope}
|
id={scope}
|
||||||
checked={field.value?.includes(scope)}
|
checked={field.value?.includes(scope)}
|
||||||
onCheckedChange={(checked) => {
|
onCheckedChange={(checked) => {
|
||||||
return checked
|
return checked
|
||||||
? field.onChange([...field.value, scope])
|
? field.onChange([...field.value, scope])
|
||||||
: field.onChange(
|
: field.onChange(
|
||||||
field.value?.filter((value: string) => value !== scope)
|
field.value?.filter(
|
||||||
|
(value: string) => value !== scope && value !== method
|
||||||
|
)
|
||||||
);
|
);
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
<div className="grid gap-1.5 leading-none">
|
<div className="grid gap-1.5 leading-none">
|
||||||
<label
|
<label
|
||||||
htmlFor={scope}
|
htmlFor={scope}
|
||||||
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 peer-disabled:cursor-not-allowed peer-disabled:opacity-70 ${
|
||||||
|
isCovered ? "hover:cursor-not-allowed opacity-70" : "hover:cursor-pointer"
|
||||||
|
}`}
|
||||||
>
|
>
|
||||||
{method == "admin" && (
|
{method == "admin" && (
|
||||||
<span className="text-slate-500">{scope.split(":")[1]} : </span>
|
<span className="text-slate-500">{scope.split(":")[1]} : </span>
|
||||||
|
|
|
@ -19,7 +19,6 @@ interface ScopeSectionProps {
|
||||||
const ScopeSection: React.FC<ScopeSectionProps> = ({ info, field }) => {
|
const ScopeSection: React.FC<ScopeSectionProps> = ({ info, field }) => {
|
||||||
const { method, description, scopes, label } = info;
|
const { method, description, scopes, label } = info;
|
||||||
|
|
||||||
console.log(field);
|
|
||||||
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">
|
||||||
<div className="flex justify-between">
|
<div className="flex justify-between">
|
||||||
|
|
Loading…
Reference in a new issue