Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding UnicoreCMS #33

Merged
merged 1 commit into from
May 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/features/authentication-unicorecms-form/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { AuthenticationFormUniCoreCMS } from "@/features/authentication-unicorecms-form/ui/AuthenticationFormUniCoreCMS";
11 changes: 11 additions & 0 deletions src/features/authentication-unicorecms-form/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
@@ -0,0 +1,80 @@
"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, FormItem, FormLabel, FormMessage } from "@/shared/ui/form";
import { Icons } from "@/shared/ui/icons";
import { Input } from "@/shared/ui/input";
import { AuthenticationType } from "@/shared/enums";

import { IntegrationFormSchemaType, integrationSchema } from "../lib/static";

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

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

const { mutateAsync, isPending } = useEditIntegration();

const form = useForm<IntegrationFormSchemaType>({
values: {
endpoint:
integration.authType === AuthenticationType.AUTHENTICATION_TYPE_UNICORECMS
? String(integration.endpoint)
: "",
authType:
integration.authType === AuthenticationType.AUTHENTICATION_TYPE_UNICORECMS
? integration.authType
: AuthenticationType.AUTHENTICATION_TYPE_UNICORECMS,
},
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>Введите ссылку на Ваш Backend</FormLabel>
<FormControl>
<Input placeholder="Введите ссылку на Ваш Backend" {...form.register("endpoint")} />
</FormControl>
{form.formState.errors.endpoint && (
<FormMessage>{form.formState.errors.endpoint.message}</FormMessage>
)}
</FormItem>

<Button
type="submit"
className="w-fit ml-auto"
disabled={isPending || !form.formState.isDirty}
>
{isPending && <Icons.spinner className="mr-2 h-4 w-4 animate-spin" />}
Сохранить
</Button>
</form>
</Form>
</div>
);
}
2 changes: 2 additions & 0 deletions src/shared/enums/integration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export enum AuthenticationType {
AUTHENTICATION_TYPE_ANY = 2, // Разрешена авторизация под любым логином и паролем
AUTHENTICATION_TYPE_AZURIOM = 3, // Разрешена авторизация под любым логином и паролем
AUTHENTICATION_TYPE_EASY_CABINET = 4, // Авторизация через EasyCabinet
AUTHENTICATION_TYPE_UNICORECMS = 5, // Авторизация через UniCoreCMS
}

export enum AuthenticationTypeOption {
Expand All @@ -12,4 +13,5 @@ export enum AuthenticationTypeOption {
"OPTION_2" = "Any", // Разрешена авторизация под любым логином и паролем
"OPTION_3" = "Azuriom", // Разрешена авторизация под любым логином и паролем
"OPTION_4" = "EasyCabinet", // Авторизация через EasyCabinet
"OPTION_5" = "UniCoreCMS", // Авторизация через UniCoreCMS
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { AuthenticationFormDle } from "@/features/authentication-dle-form";
import { AuthenticationAnyForm } from "@/features/authentication-any-form";
import { AuthenticationFormAzuriom } from "@/features/authentication-azuriom-form";
import { AuthenticationFormEasycabinet } from "@/features/authentication-easycabinet-form";
import { AuthenticationFormUniCoreCMS } from "@/features/authentication-unicorecms-form";

import {
Dialog,
Expand Down Expand Up @@ -46,6 +47,8 @@ export function ChooseAuthenticationMethodDialog() {
Number(authenticationTab) === AuthenticationType.AUTHENTICATION_TYPE_AZURIOM;
const isFormEasyCabinet =
Number(authenticationTab) === AuthenticationType.AUTHENTICATION_TYPE_EASY_CABINET;
const isFormUniCoreCMS =
Number(authenticationTab) === AuthenticationType.AUTHENTICATION_TYPE_UNICORECMS;

return (
<Dialog open={open} onOpenChange={onOpenChange}>
Expand Down Expand Up @@ -93,6 +96,7 @@ export function ChooseAuthenticationMethodDialog() {
{isFormAny && <AuthenticationAnyForm onOpenChange={onOpenChange} />}
{isFormAzuriom && <AuthenticationFormAzuriom onOpenChange={onOpenChange} />}
{isFormEasyCabinet && <AuthenticationFormEasycabinet onOpenChange={onOpenChange} />}
{isFormUniCoreCMS && <AuthenticationFormUniCoreCMS onOpenChange={onOpenChange} />}
</div>
</DialogContent>
</Dialog>
Expand Down
Loading