Skip to content

Commit

Permalink
GL-25: Обновилены интеграции аутентификации
Browse files Browse the repository at this point in the history
  • Loading branch information
Терентьев Вадим Алексеевич committed May 4, 2024
1 parent 81fd28d commit 8697349
Show file tree
Hide file tree
Showing 22 changed files with 358 additions and 78 deletions.
16 changes: 8 additions & 8 deletions src/entities/Table/ui/items/data-table-view-options.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
'use client';
"use client";

import { Table } from '@tanstack/react-table';
import { Table } from "@tanstack/react-table";

import { DropdownMenuTrigger } from '@radix-ui/react-dropdown-menu';
import { MixerHorizontalIcon } from '@radix-ui/react-icons';
import { DropdownMenuTrigger } from "@radix-ui/react-dropdown-menu";
import { MixerHorizontalIcon } from "@radix-ui/react-icons";

import { Button } from '@/shared/ui/button';
import { Button } from "@/shared/ui/button";
import {
DropdownMenu,
DropdownMenuCheckboxItem,
DropdownMenuContent,
DropdownMenuLabel,
DropdownMenuSeparator,
} from '@/shared/ui/dropdown-menu';
} from "@/shared/ui/dropdown-menu";

interface DataTableViewOptionsProps<TData> {
table: Table<TData>;
Expand All @@ -32,13 +32,13 @@ export function DataTableViewOptions<TData>({ table }: DataTableViewOptionsProps
<DropdownMenuSeparator />
{table
.getAllColumns()
.filter((column) => typeof column.accessorFn !== 'undefined' && column.getCanHide())
.filter((column) => typeof column.accessorFn !== "undefined" && column.getCanHide())
.map((column) => (
<DropdownMenuCheckboxItem
key={column.id}
className="capitalize"
checked={column.getIsVisible()}
onCheckedChange={(value) => column.toggleVisibility(!!value)}
onCheckedChange={(value) => column.toggleVisibility(value)}
>
{column.id}
</DropdownMenuCheckboxItem>
Expand Down
1 change: 1 addition & 0 deletions src/features/authentication-form-any/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { AuthenticationFormAny } from "@/features/authentication-form-any/ui/AuthenticationFormAny";
44 changes: 44 additions & 0 deletions src/features/authentication-form-any/ui/AuthenticationFormAny.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
"use client";

import React from "react";

import { useEditIntegration } from "@/shared/hooks";
import { cn } from "@/shared/lib/utils";
import { Button } from "@/shared/ui/button";
import { Icons } from "@/shared/ui/icons";
import { AuthenticationType } from "@/shared/enums";
import { Alert, AlertDescription, AlertTitle } from "@/shared/ui/alert";
import { ExclamationTriangleIcon } from "@radix-ui/react-icons";

interface SignInFormProps extends React.HTMLAttributes<HTMLDivElement> {
onOpenChange: (open: boolean) => void;
}

export function AuthenticationFormAny({ className, onOpenChange, ...props }: SignInFormProps) {
const { mutateAsync, isPending } = useEditIntegration();

const onSubmit = async () => {
await mutateAsync({
authType: AuthenticationType.AUTHENTICATION_TYPE_ANY,
endpoint: "https://localhost",
}).then(() => {
onOpenChange(false);
});
};

return (
<div className={cn("grid gap-4", className)} {...props}>
<Alert variant="destructive">
<ExclamationTriangleIcon className="h-4 w-4" />
<AlertTitle>Внимание!</AlertTitle>
<AlertDescription>
Данный метод <strong>разрешит</strong> любую аутентификацию со стороны лаунчера
</AlertDescription>
</Alert>
<Button type="submit" className="w-fit ml-auto" disabled={isPending} onClick={onSubmit}>
{isPending && <Icons.spinner className="mr-2 h-4 w-4 animate-spin" />}
Сохранить
</Button>
</div>
);
}
1 change: 1 addition & 0 deletions src/features/authentication-form-azuriom/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { AuthenticationFormAzuriom } from "@/features/authentication-form-azuriom/ui/AuthenticationFormAzuriom";
11 changes: 11 additions & 0 deletions src/features/authentication-form-azuriom/lib/static.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { z } from "zod";

export const integrationSchema = z.object({
authType: z.number(),
endpoint: z
.string()
.min(1, { message: "Вы не заполнили поле" })
.transform((v) => v.trim()),
});

export type IntegrationFormSchemaType = z.infer<typeof integrationSchema>;
Original file line number Diff line number Diff line change
Expand Up @@ -6,30 +6,34 @@ import { SubmitHandler, useForm } from "react-hook-form";

import { zodResolver } from "@hookform/resolvers/zod";

import {
IntegrationFormSchemaType,
integrationSchema,
} from "@/features/integration-form/lib/static";
import { useCurrentIntegration, useEditIntegration } from "@/shared/hooks";
import { useEditIntegration, useGetActiveAuthIntegrations } from "@/shared/hooks";
import { cn } from "@/shared/lib/utils";
import { Button } from "@/shared/ui/button";
import { Form, FormControl, FormItem, FormLabel, FormMessage } from "@/shared/ui/form";
import { Icons } from "@/shared/ui/icons";
import { Input } from "@/shared/ui/input";
import { IntegrationFormSchemaType, integrationSchema } from "../lib/static";
import { AuthenticationType } from "@/shared/enums";

interface SignInFormProps extends React.HTMLAttributes<HTMLDivElement> {
onOpenChange: (open: boolean) => void;
}

export function IntegrationForm({ className, onOpenChange, ...props }: SignInFormProps) {
const currentIntegration = useCurrentIntegration();
export function AuthenticationFormAzuriom({ className, onOpenChange, ...props }: SignInFormProps) {
const { data: integration } = useGetActiveAuthIntegrations();

const { mutateAsync, isPending } = useEditIntegration();

const form = useForm<IntegrationFormSchemaType>({
values: {
endpoint: currentIntegration?.endpoint || "",
authType: currentIntegration?.authType || 1,
endpoint:
integration.authType === AuthenticationType.AUTHENTICATION_TYPE_AZURIOM
? String(integration.endpoint)
: "",
authType:
integration.authType === AuthenticationType.AUTHENTICATION_TYPE_AZURIOM
? integration.authType
: AuthenticationType.AUTHENTICATION_TYPE_AZURIOM,
},
resolver: zodResolver(integrationSchema),
});
Expand All @@ -47,9 +51,9 @@ export function IntegrationForm({ className, onOpenChange, ...props }: SignInFor
<Form {...form}>
<form className="flex flex-col space-y-6" onSubmit={form.handleSubmit(onSubmit)}>
<FormItem>
<FormLabel>Введите эндпоинт</FormLabel>
<FormLabel>Введите ссылку на Ваш сайт</FormLabel>
<FormControl>
<Input placeholder="Введите эндпоинт" {...form.register("endpoint")} />
<Input placeholder="Введите ссылку на Ваш сайт" {...form.register("endpoint")} />
</FormControl>
{form.formState.errors.endpoint && (
<FormMessage>{form.formState.errors.endpoint.message}</FormMessage>
Expand Down
1 change: 1 addition & 0 deletions src/features/authentication-form-dle/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { AuthenticationFormDle } from "@/features/authentication-form-dle/ui/AuthenticationFormDle";
11 changes: 11 additions & 0 deletions src/features/authentication-form-dle/lib/static.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { z } from "zod";

export const integrationSchema = z.object({
authType: z.number(),
endpoint: z
.string()
.min(1, { message: "Вы не заполнили поле" })
.transform((v) => v.trim()),
});

export type IntegrationFormSchemaType = z.infer<typeof integrationSchema>;
90 changes: 90 additions & 0 deletions src/features/authentication-form-dle/ui/AuthenticationFormDle.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
"use client";

import React from "react";

import { SubmitHandler, useForm } from "react-hook-form";

import { zodResolver } from "@hookform/resolvers/zod";
import { useEditIntegration, useGetActiveAuthIntegrations } from "@/shared/hooks";
import { cn } from "@/shared/lib/utils";
import { Button } from "@/shared/ui/button";
import {
Form,
FormControl,
FormDescription,
FormItem,
FormLabel,
FormMessage,
} from "@/shared/ui/form";
import { Icons } from "@/shared/ui/icons";
import { Input } from "@/shared/ui/input";
import { IntegrationFormSchemaType, integrationSchema } from "../lib/static";
import { AuthenticationType } from "@/shared/enums";
import Link from "next/link";

interface SignInFormProps extends React.HTMLAttributes<HTMLDivElement> {
onOpenChange: (open: boolean) => void;
}

export function AuthenticationFormDle({ className, onOpenChange, ...props }: SignInFormProps) {
const { data: integration } = useGetActiveAuthIntegrations();

const { mutateAsync, isPending } = useEditIntegration();

const form = useForm<IntegrationFormSchemaType>({
values: {
endpoint:
integration.authType === AuthenticationType.AUTHENTICATION_TYPE_DATALIFE_ENGINE
? String(integration.endpoint)
: "",
authType:
integration.authType === AuthenticationType.AUTHENTICATION_TYPE_DATALIFE_ENGINE
? integration.authType
: AuthenticationType.AUTHENTICATION_TYPE_DATALIFE_ENGINE,
},
resolver: zodResolver(integrationSchema),
});

const onSubmit: SubmitHandler<IntegrationFormSchemaType> = async (
data: IntegrationFormSchemaType,
) => {
await mutateAsync(data).then(() => {
onOpenChange(false);
});
};

return (
<div className={cn("grid gap-4", className)} {...props}>
<Form {...form}>
<form className="flex flex-col space-y-6" onSubmit={form.handleSubmit(onSubmit)}>
<FormItem>
<FormLabel>Введите эндпоинт</FormLabel>
<FormControl>
<Input placeholder="Введите эндпоинт" {...form.register("endpoint")} />
</FormControl>

{form.formState.errors.endpoint ? (
<FormMessage>{form.formState.errors.endpoint.message}</FormMessage>
) : (
<FormDescription>
Не знаете где взять файл auth.php?{" "}
<Link
className="font-medium text-blue-600 dark:text-blue-500 hover:underline"
href="https://stackoverflow.com/"
passHref={true}
target="_blank"
>
Скачайте по ссылке
</Link>
</FormDescription>
)}
</FormItem>
<Button type="submit" className="w-fit ml-auto" disabled={isPending}>
{isPending && <Icons.spinner className="mr-2 h-4 w-4 animate-spin" />}
Сохранить
</Button>
</form>
</Form>
</div>
);
}
1 change: 1 addition & 0 deletions src/features/authentication-form-undefined/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { AuthenticationFormAzuriom } from "@/features/authentication-form-azuriom/ui/AuthenticationFormAzuriom";
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
"use client";

import React from "react";

import { useEditIntegration } from "@/shared/hooks";
import { cn } from "@/shared/lib/utils";
import { Button } from "@/shared/ui/button";
import { Icons } from "@/shared/ui/icons";
import { AuthenticationType } from "@/shared/enums";
import { Alert, AlertDescription, AlertTitle } from "@/shared/ui/alert";
import { ExclamationTriangleIcon } from "@radix-ui/react-icons";

interface SignInFormProps extends React.HTMLAttributes<HTMLDivElement> {
onOpenChange: (open: boolean) => void;
}

export function AuthenticationFormUndefined({
className,
onOpenChange,
...props
}: SignInFormProps) {
const { mutateAsync, isPending } = useEditIntegration();

const onSubmit = async () => {
await mutateAsync({
authType: AuthenticationType.AUTHENTICATION_TYPE_UNDEFINED,
endpoint: "https://localhost",
}).then(() => {
onOpenChange(false);
});
};

return (
<div className={cn("grid gap-4", className)} {...props}>
<Alert variant="destructive">
<ExclamationTriangleIcon className="h-4 w-4" />
<AlertTitle>Внимание!</AlertTitle>
<AlertDescription>
Данный метод <strong>запретит</strong> любую аутентификацию со стороны лаунчера
</AlertDescription>
</Alert>
<Button type="submit" className="w-fit ml-auto" disabled={isPending} onClick={onSubmit}>
{isPending && <Icons.spinner className="mr-2 h-4 w-4 animate-spin" />}
Сохранить
</Button>
</div>
);
}
1 change: 0 additions & 1 deletion src/features/integration-form/index.ts

This file was deleted.

8 changes: 0 additions & 8 deletions src/features/integration-form/lib/static.ts

This file was deleted.

2 changes: 1 addition & 1 deletion src/features/sentry-connect-form/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export { IntegrationForm } from '@/features/integration-form/ui/IntegrationForm';
export { SentryConnectForm } from "@/features/sentry-connect-form/ui/SentryConnectForm";
2 changes: 2 additions & 0 deletions src/screens/Integrations/ui/Integrations.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ export const IntegrationsPage = () => {
title="Аутентификация"
description="Синхронизация и управление данными о пользователях на платформе"
action={onAuthenticationDialogToggle}
status={"CONNECTED"}
buttonText={"Изменить"}
/>
<IntegrationCard
title="Сборка лаунчера"
Expand Down
4 changes: 3 additions & 1 deletion src/shared/api/contracts/integrations/schemas.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { AuthenticationType } from "@/shared/enums";

export type AuthIntegrationBaseEntity = {
name: string;
authType: number;
authType: AuthenticationType;
endpoint: string | null;
};

Expand Down
5 changes: 3 additions & 2 deletions src/shared/enums/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export * from './auth';
export * from './systems';
export * from "./auth";
export * from "./systems";
export * from "./integration";
13 changes: 13 additions & 0 deletions src/shared/enums/integration.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
export enum AuthenticationType {
AUTHENTICATION_TYPE_UNDEFINED = 0, // Запрещена авторизация
AUTHENTICATION_TYPE_DATALIFE_ENGINE = 1, // Авторизация через DLE
AUTHENTICATION_TYPE_ANY = 2, // Разрешена авторизация под любым логином и паролем
AUTHENTICATION_TYPE_AZURIOM = 3, // Разрешена авторизация под любым логином и паролем
}

export enum AuthenticationTypeOption {
"OPTION_0" = "Undefined", // Запрещена авторизация
"OPTION_1" = "DataLife Engine", // Авторизация через DLE
"OPTION_2" = "Any", // Разрешена авторизация под любым логином и паролем
"OPTION_3" = "Azuriom", // Разрешена авторизация под любым логином и паролем
}
Loading

0 comments on commit 8697349

Please sign in to comment.