lint
This commit is contained in:
parent
8c279b5cd7
commit
ad68fac107
|
|
@ -1,9 +1,8 @@
|
||||||
"use client";
|
"use client";
|
||||||
|
|
||||||
|
import ClientError from "@/core/error/ClientError";
|
||||||
import createUserAction from "@/modules/auth/actions/createUserAction";
|
import createUserAction from "@/modules/auth/actions/createUserAction";
|
||||||
import createUser from "@/modules/auth/actions/createUserAction";
|
|
||||||
import { CreateUserSchema } from "@/modules/auth/formSchemas/CreateUserFormSchema";
|
import { CreateUserSchema } from "@/modules/auth/formSchemas/CreateUserFormSchema";
|
||||||
import DashboardError from "@/modules/dashboard/errors/DashboardError";
|
|
||||||
import withServerAction from "@/modules/dashboard/utils/withServerAction";
|
import withServerAction from "@/modules/dashboard/utils/withServerAction";
|
||||||
import {
|
import {
|
||||||
Paper,
|
Paper,
|
||||||
|
|
@ -17,10 +16,11 @@ import {
|
||||||
} from "@mantine/core";
|
} from "@mantine/core";
|
||||||
import { useForm } from "@mantine/form";
|
import { useForm } from "@mantine/form";
|
||||||
import { showNotification } from "@mantine/notifications";
|
import { showNotification } from "@mantine/notifications";
|
||||||
import React, { useEffect, useState } from "react";
|
import React from "react";
|
||||||
|
|
||||||
export default function RegisterPage() {
|
export default function RegisterPage() {
|
||||||
const [errorMessage, setErrorMessage] = useState("");
|
//TODO: Display error message
|
||||||
|
// const [errorMessage, setErrorMessage] = useState("");
|
||||||
|
|
||||||
const form = useForm<CreateUserSchema>({
|
const form = useForm<CreateUserSchema>({
|
||||||
initialValues: {
|
initialValues: {
|
||||||
|
|
@ -43,24 +43,24 @@ export default function RegisterPage() {
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
const handleSubmit = async (values: CreateUserSchema) => {
|
const handleSubmit = async () => {
|
||||||
withServerAction(createUserAction, form.values)
|
withServerAction(createUserAction, form.values)
|
||||||
.then((response) => {
|
.then(() => {
|
||||||
showNotification({message: "Register Success", color: "green"})
|
showNotification({message: "Register Success", color: "green"})
|
||||||
})
|
})
|
||||||
.catch((e) => {
|
.catch((e) => {
|
||||||
if (e instanceof DashboardError) {
|
if (e instanceof ClientError) {
|
||||||
if (e.errorCode === "INVALID_FORM_DATA") {
|
if (e.errorCode === "INVALID_FORM_DATA") {
|
||||||
form.setErrors(e.formErrors ?? {});
|
form.setErrors(e.formErrors ?? {});
|
||||||
} else {
|
} else {
|
||||||
setErrorMessage(`ERROR: ${e.message} (${e.errorCode})`);
|
// setErrorMessage(`ERROR: ${e.message} (${e.errorCode})`);
|
||||||
}
|
}
|
||||||
} else if (e instanceof Error) {
|
} else if (e instanceof Error) {
|
||||||
setErrorMessage(`ERROR: ${e.message}`);
|
// setErrorMessage(`ERROR: ${e.message}`);
|
||||||
} else {
|
} else {
|
||||||
setErrorMessage(
|
// setErrorMessage(
|
||||||
`Unkown error is occured. Please contact administrator`
|
// `Unkown error is occured. Please contact administrator`
|
||||||
);
|
// );
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
};
|
};
|
||||||
|
|
@ -72,7 +72,7 @@ export default function RegisterPage() {
|
||||||
Register
|
Register
|
||||||
</Text>
|
</Text>
|
||||||
<form
|
<form
|
||||||
onSubmit={form.onSubmit((values) => handleSubmit(values))}
|
onSubmit={form.onSubmit(() => handleSubmit())}
|
||||||
>
|
>
|
||||||
<Stack>
|
<Stack>
|
||||||
<TextInput
|
<TextInput
|
||||||
|
|
|
||||||
|
|
@ -3,10 +3,7 @@ import handleCatchApi from "@/core/utils/handleCatchApi";
|
||||||
import AuthError from "@/modules/auth/error/AuthError";
|
import AuthError from "@/modules/auth/error/AuthError";
|
||||||
import signInSchema from "@/modules/auth/formSchemas/signInSchema";
|
import signInSchema from "@/modules/auth/formSchemas/signInSchema";
|
||||||
import signIn from "@/modules/auth/services/signIn";
|
import signIn from "@/modules/auth/services/signIn";
|
||||||
import getTokenFromHeaders from "@/modules/auth/utils/getTokenFromHeaders";
|
|
||||||
import { headers } from "next/headers";
|
|
||||||
import { NextRequest, NextResponse } from "next/server";
|
import { NextRequest, NextResponse } from "next/server";
|
||||||
import { json } from "stream/consumers";
|
|
||||||
|
|
||||||
export const dynamic = "force-dynamic";
|
export const dynamic = "force-dynamic";
|
||||||
|
|
||||||
|
|
|
||||||
43
src/core/error/ClientError.ts
Normal file
43
src/core/error/ClientError.ts
Normal file
|
|
@ -0,0 +1,43 @@
|
||||||
|
import "client-only"
|
||||||
|
export const ClientErrorCodes = ["UNKNOWN_ERROR", "UNSUPPORTED_CONTENT_TYPE"] as const;
|
||||||
|
|
||||||
|
interface ErrorOptions {
|
||||||
|
message?: string;
|
||||||
|
errorCode: (typeof ClientErrorCodes)[number] | (string & {});
|
||||||
|
statusCode?: number
|
||||||
|
formErrors?: Record<string, string>
|
||||||
|
}
|
||||||
|
|
||||||
|
class ClientError extends Error {
|
||||||
|
public readonly errorCode: ErrorOptions['errorCode'];
|
||||||
|
public readonly statusCode: ErrorOptions['statusCode'];
|
||||||
|
public readonly formErrors?: ErrorOptions['formErrors']
|
||||||
|
|
||||||
|
constructor(options: ErrorOptions) {
|
||||||
|
super(options.message ?? "Undetermined Error");
|
||||||
|
this.errorCode = options.errorCode ?? "UNKNOWN_ERROR";
|
||||||
|
this.statusCode = options.statusCode ?? 500;
|
||||||
|
this.formErrors = options.formErrors;
|
||||||
|
|
||||||
|
Object.setPrototypeOf(this, new.target.prototype);
|
||||||
|
}
|
||||||
|
|
||||||
|
getActionResponseObject() {
|
||||||
|
return {
|
||||||
|
success: false,
|
||||||
|
error: {
|
||||||
|
message: this.message,
|
||||||
|
errorCode: this.errorCode,
|
||||||
|
},
|
||||||
|
} as const;
|
||||||
|
}
|
||||||
|
|
||||||
|
getRestApiResponseObject(){
|
||||||
|
return {
|
||||||
|
message: this.message,
|
||||||
|
errorCode: this.errorCode
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default ClientError;
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
|
import "server-only"
|
||||||
import { appendFileSync } from "node:fs";
|
import { appendFileSync } from "node:fs";
|
||||||
import { format } from 'date-fns';
|
import { format } from 'date-fns';
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,6 @@
|
||||||
"use server";
|
"use server";
|
||||||
import { z } from "zod";
|
|
||||||
import prisma from "@/core/db";
|
|
||||||
import { cookies } from "next/headers";
|
import { cookies } from "next/headers";
|
||||||
import { redirect } from "next/navigation";
|
import { redirect } from "next/navigation";
|
||||||
import { hashPassword } from "../utils/hashPassword";
|
|
||||||
import { createJwtToken } from "../utils/createJwtToken";
|
|
||||||
import createUser from "../services/createUser";
|
import createUser from "../services/createUser";
|
||||||
import ServerResponseAction from "@/modules/dashboard/types/ServerResponseAction";
|
import ServerResponseAction from "@/modules/dashboard/types/ServerResponseAction";
|
||||||
import handleCatch from "@/modules/dashboard/utils/handleCatch";
|
import handleCatch from "@/modules/dashboard/utils/handleCatch";
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
import DashboardError from "../errors/DashboardError";
|
import ClientError from "@/core/error/ClientError";
|
||||||
import ServerResponseAction from "../types/ServerResponseAction";
|
import ServerResponseAction from "../types/ServerResponseAction";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -21,7 +21,7 @@ async function withServerAction<T, Args extends unknown[] = []>(
|
||||||
} else {
|
} else {
|
||||||
if (result.dashboardError && result.error) {
|
if (result.dashboardError && result.error) {
|
||||||
const errorDetails = result.error;
|
const errorDetails = result.error;
|
||||||
throw new DashboardError({
|
throw new ClientError({
|
||||||
message: errorDetails.message,
|
message: errorDetails.message,
|
||||||
errorCode: errorDetails.errorCode,
|
errorCode: errorDetails.errorCode,
|
||||||
formErrors: errorDetails.errors,
|
formErrors: errorDetails.errors,
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,4 @@
|
||||||
"use client";
|
"use client";
|
||||||
import { useRouter } from "next/navigation";
|
|
||||||
import React, { useState } from "react";
|
import React, { useState } from "react";
|
||||||
import {
|
import {
|
||||||
Button,
|
Button,
|
||||||
|
|
@ -9,11 +8,9 @@ import {
|
||||||
Alert,
|
Alert,
|
||||||
} from "@mantine/core";
|
} from "@mantine/core";
|
||||||
import { showNotification } from "@/utils/notifications";
|
import { showNotification } from "@/utils/notifications";
|
||||||
import { error } from "console";
|
|
||||||
import { revalidatePath } from "next/cache";
|
|
||||||
import withServerAction from "@/modules/dashboard/utils/withServerAction";
|
import withServerAction from "@/modules/dashboard/utils/withServerAction";
|
||||||
import deletePermission from "../actions/deletePermission";
|
import deletePermission from "../actions/deletePermission";
|
||||||
import DashboardError from "@/modules/dashboard/errors/DashboardError";
|
import ClientError from "@/core/error/ClientError";
|
||||||
|
|
||||||
export interface DeleteModalProps {
|
export interface DeleteModalProps {
|
||||||
data?: {
|
data?: {
|
||||||
|
|
@ -24,8 +21,6 @@ export interface DeleteModalProps {
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function DeleteModal(props: DeleteModalProps) {
|
export default function DeleteModal(props: DeleteModalProps) {
|
||||||
const router = useRouter();
|
|
||||||
|
|
||||||
const [isSubmitting, setSubmitting] = useState(false);
|
const [isSubmitting, setSubmitting] = useState(false);
|
||||||
const [errorMessage, setErrorMessage] = useState("");
|
const [errorMessage, setErrorMessage] = useState("");
|
||||||
|
|
||||||
|
|
@ -51,7 +46,7 @@ export default function DeleteModal(props: DeleteModalProps) {
|
||||||
props.onClose()
|
props.onClose()
|
||||||
})
|
})
|
||||||
.catch((e) => {
|
.catch((e) => {
|
||||||
if (e instanceof DashboardError){
|
if (e instanceof ClientError){
|
||||||
setErrorMessage(`ERROR: ${e.message} (${e.errorCode})`)
|
setErrorMessage(`ERROR: ${e.message} (${e.errorCode})`)
|
||||||
}
|
}
|
||||||
else if (e instanceof Error) {
|
else if (e instanceof Error) {
|
||||||
|
|
|
||||||
|
|
@ -4,25 +4,23 @@ import {
|
||||||
Flex,
|
Flex,
|
||||||
Modal,
|
Modal,
|
||||||
Stack,
|
Stack,
|
||||||
Switch,
|
|
||||||
TextInput,
|
TextInput,
|
||||||
Textarea,
|
Textarea,
|
||||||
Button,
|
Button,
|
||||||
ScrollArea,
|
ScrollArea,
|
||||||
Checkbox,
|
Checkbox,
|
||||||
Skeleton,
|
Skeleton,
|
||||||
Fieldset,
|
|
||||||
Alert,
|
Alert,
|
||||||
} from "@mantine/core";
|
} from "@mantine/core";
|
||||||
import { useForm, zodResolver } from "@mantine/form";
|
import { useForm, zodResolver } from "@mantine/form";
|
||||||
import { useRouter } from "next/navigation";
|
import { useRouter } from "next/navigation";
|
||||||
import React, { useCallback, useEffect, useState } from "react";
|
import React, { useEffect, useState } from "react";
|
||||||
import { TbDeviceFloppy } from "react-icons/tb";
|
import { TbDeviceFloppy } from "react-icons/tb";
|
||||||
import permissionFormDataSchema, { PermissionFormData } from "../formSchemas/PermissionFormData";
|
import permissionFormDataSchema, { PermissionFormData } from "../formSchemas/PermissionFormData";
|
||||||
import getPermissionById from "../actions/getPermissionById";
|
import getPermissionById from "../actions/getPermissionById";
|
||||||
import withServerAction from "@/modules/dashboard/utils/withServerAction";
|
import withServerAction from "@/modules/dashboard/utils/withServerAction";
|
||||||
import upsertPermission from "../actions/upsertPermission";
|
import upsertPermission from "../actions/upsertPermission";
|
||||||
import DashboardError from "@/modules/dashboard/errors/DashboardError";
|
import ClientError from "@/core/error/ClientError";
|
||||||
|
|
||||||
export interface ModalProps {
|
export interface ModalProps {
|
||||||
title: string;
|
title: string;
|
||||||
|
|
@ -103,7 +101,7 @@ export default function FormModal(props: ModalProps) {
|
||||||
closeModal();
|
closeModal();
|
||||||
})
|
})
|
||||||
.catch((e) => {
|
.catch((e) => {
|
||||||
if (e instanceof DashboardError) {
|
if (e instanceof ClientError) {
|
||||||
if (e.errorCode === "INVALID_FORM_DATA") {
|
if (e.errorCode === "INVALID_FORM_DATA") {
|
||||||
form.setErrors(e.formErrors ?? {});
|
form.setErrors(e.formErrors ?? {});
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,4 @@
|
||||||
"use client";
|
"use client";
|
||||||
import { useRouter } from "next/navigation";
|
|
||||||
import React, { useState } from "react";
|
import React, { useState } from "react";
|
||||||
import {
|
import {
|
||||||
Button,
|
Button,
|
||||||
|
|
@ -11,7 +10,7 @@ import {
|
||||||
import { showNotification } from "@/utils/notifications";
|
import { showNotification } from "@/utils/notifications";
|
||||||
import withServerAction from "@/modules/dashboard/utils/withServerAction";
|
import withServerAction from "@/modules/dashboard/utils/withServerAction";
|
||||||
import deleteRole from "../actions/deleteRole";
|
import deleteRole from "../actions/deleteRole";
|
||||||
import DashboardError from "@/modules/dashboard/errors/DashboardError";
|
import ClientError from "@/core/error/ClientError";
|
||||||
|
|
||||||
export interface DeleteModalProps {
|
export interface DeleteModalProps {
|
||||||
data?: {
|
data?: {
|
||||||
|
|
@ -22,7 +21,6 @@ export interface DeleteModalProps {
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function DeleteModal(props: DeleteModalProps) {
|
export default function DeleteModal(props: DeleteModalProps) {
|
||||||
const router = useRouter();
|
|
||||||
|
|
||||||
const [isSubmitting, setSubmitting] = useState(false);
|
const [isSubmitting, setSubmitting] = useState(false);
|
||||||
const [errorMessage, setErrorMessage] = useState("");
|
const [errorMessage, setErrorMessage] = useState("");
|
||||||
|
|
@ -49,7 +47,7 @@ export default function DeleteModal(props: DeleteModalProps) {
|
||||||
props.onClose()
|
props.onClose()
|
||||||
})
|
})
|
||||||
.catch((e) => {
|
.catch((e) => {
|
||||||
if (e instanceof DashboardError){
|
if (e instanceof ClientError){
|
||||||
setErrorMessage(`ERROR: ${e.message} (${e.errorCode})`)
|
setErrorMessage(`ERROR: ${e.message} (${e.errorCode})`)
|
||||||
}
|
}
|
||||||
else if (e instanceof Error) {
|
else if (e instanceof Error) {
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,6 @@ import {
|
||||||
Flex,
|
Flex,
|
||||||
Modal,
|
Modal,
|
||||||
Stack,
|
Stack,
|
||||||
Switch,
|
|
||||||
TextInput,
|
TextInput,
|
||||||
Textarea,
|
Textarea,
|
||||||
Button,
|
Button,
|
||||||
|
|
@ -17,15 +16,14 @@ import {
|
||||||
} from "@mantine/core";
|
} from "@mantine/core";
|
||||||
import { useForm, zodResolver } from "@mantine/form";
|
import { useForm, zodResolver } from "@mantine/form";
|
||||||
import { useRouter } from "next/navigation";
|
import { useRouter } from "next/navigation";
|
||||||
import React, { useCallback, useEffect, useMemo, useState } from "react";
|
import React, { useEffect, useState } from "react";
|
||||||
import { TbDeviceFloppy } from "react-icons/tb";
|
import { TbDeviceFloppy } from "react-icons/tb";
|
||||||
import { string } from "zod";
|
|
||||||
import roleFormDataSchema, { RoleFormData } from "../formSchemas/RoleFormData";
|
import roleFormDataSchema, { RoleFormData } from "../formSchemas/RoleFormData";
|
||||||
import getAllPermissions from "@/modules/permission/actions/getAllPermissions";
|
import getAllPermissions from "@/modules/permission/actions/getAllPermissions";
|
||||||
import withServerAction from "@/modules/dashboard/utils/withServerAction";
|
import withServerAction from "@/modules/dashboard/utils/withServerAction";
|
||||||
import DashboardError from "@/modules/dashboard/errors/DashboardError";
|
|
||||||
import getRoleById from "../actions/getRoleById";
|
import getRoleById from "../actions/getRoleById";
|
||||||
import upsertRole from "../actions/upsertRole";
|
import upsertRole from "../actions/upsertRole";
|
||||||
|
import ClientError from "@/core/error/ClientError";
|
||||||
|
|
||||||
export interface ModalProps {
|
export interface ModalProps {
|
||||||
title: string;
|
title: string;
|
||||||
|
|
@ -74,7 +72,7 @@ export default function FormModal(props: ModalProps) {
|
||||||
setAllPermissions(response.data);
|
setAllPermissions(response.data);
|
||||||
})
|
})
|
||||||
.catch((e) => {
|
.catch((e) => {
|
||||||
if (e instanceof DashboardError) {
|
if (e instanceof ClientError) {
|
||||||
setErrorMessage(`ERROR: ${e.message} (${e.errorCode})`);
|
setErrorMessage(`ERROR: ${e.message} (${e.errorCode})`);
|
||||||
} else if (e instanceof Error) {
|
} else if (e instanceof Error) {
|
||||||
setErrorMessage(`ERROR: ${e.message}`);
|
setErrorMessage(`ERROR: ${e.message}`);
|
||||||
|
|
@ -113,7 +111,7 @@ export default function FormModal(props: ModalProps) {
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
.catch((e) => {
|
.catch((e) => {
|
||||||
if (e instanceof DashboardError) {
|
if (e instanceof ClientError) {
|
||||||
setErrorMessage(`ERROR: ${e.message} (${e.errorCode})`);
|
setErrorMessage(`ERROR: ${e.message} (${e.errorCode})`);
|
||||||
} else if (e instanceof Error) {
|
} else if (e instanceof Error) {
|
||||||
setErrorMessage(`ERROR: ${e.message}`);
|
setErrorMessage(`ERROR: ${e.message}`);
|
||||||
|
|
@ -141,7 +139,7 @@ export default function FormModal(props: ModalProps) {
|
||||||
closeModal();
|
closeModal();
|
||||||
})
|
})
|
||||||
.catch((e) => {
|
.catch((e) => {
|
||||||
if (e instanceof DashboardError) {
|
if (e instanceof ClientError) {
|
||||||
if (e.errorCode === "INVALID_FORM_DATA") {
|
if (e.errorCode === "INVALID_FORM_DATA") {
|
||||||
form.setErrors(e.formErrors ?? {});
|
form.setErrors(e.formErrors ?? {});
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,6 @@ import { Text, Flex, Button } from "@mantine/core";
|
||||||
import { getCoreRowModel, useReactTable } from "@tanstack/react-table";
|
import { getCoreRowModel, useReactTable } from "@tanstack/react-table";
|
||||||
import React, { useState } from "react";
|
import React, { useState } from "react";
|
||||||
import { TbPlus } from "react-icons/tb";
|
import { TbPlus } from "react-icons/tb";
|
||||||
import getAllRoles from "../../actions/getAllRoles";
|
|
||||||
import FormModal, { ModalProps } from "../../modals/FormModal";
|
import FormModal, { ModalProps } from "../../modals/FormModal";
|
||||||
import DeleteModal, { DeleteModalProps } from "../../modals/DeleteModal";
|
import DeleteModal, { DeleteModalProps } from "../../modals/DeleteModal";
|
||||||
import createColumns from "./columns";
|
import createColumns from "./columns";
|
||||||
|
|
|
||||||
|
|
@ -1,23 +1,16 @@
|
||||||
"use client";
|
"use client";
|
||||||
import { useRouter } from "next/navigation";
|
|
||||||
import React, { useState } from "react";
|
import React, { useState } from "react";
|
||||||
import {
|
import {
|
||||||
Avatar,
|
|
||||||
Button,
|
Button,
|
||||||
Center,
|
|
||||||
Flex,
|
Flex,
|
||||||
Modal,
|
Modal,
|
||||||
ScrollArea,
|
|
||||||
Text,
|
Text,
|
||||||
Stack,
|
|
||||||
TextInput,
|
|
||||||
Title,
|
|
||||||
Alert,
|
Alert,
|
||||||
} from "@mantine/core";
|
} from "@mantine/core";
|
||||||
import { showNotification } from "@/utils/notifications";
|
import { showNotification } from "@/utils/notifications";
|
||||||
import withServerAction from "@/modules/dashboard/utils/withServerAction";
|
import withServerAction from "@/modules/dashboard/utils/withServerAction";
|
||||||
import deleteUser from "../actions/deleteUser";
|
import deleteUser from "../actions/deleteUser";
|
||||||
import DashboardError from "@/modules/dashboard/errors/DashboardError";
|
import ClientError from "@/core/error/ClientError";
|
||||||
|
|
||||||
export interface DeleteModalProps {
|
export interface DeleteModalProps {
|
||||||
data?: {
|
data?: {
|
||||||
|
|
@ -28,7 +21,6 @@ export interface DeleteModalProps {
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function UserDeleteModal(props: DeleteModalProps) {
|
export default function UserDeleteModal(props: DeleteModalProps) {
|
||||||
const router = useRouter();
|
|
||||||
|
|
||||||
const [isSubmitting, setSubmitting] = useState(false);
|
const [isSubmitting, setSubmitting] = useState(false);
|
||||||
const [errorMessage, setErrorMessage] = useState("");
|
const [errorMessage, setErrorMessage] = useState("");
|
||||||
|
|
@ -55,7 +47,7 @@ export default function UserDeleteModal(props: DeleteModalProps) {
|
||||||
props.onClose()
|
props.onClose()
|
||||||
})
|
})
|
||||||
.catch((e) => {
|
.catch((e) => {
|
||||||
if (e instanceof DashboardError){
|
if (e instanceof ClientError){
|
||||||
setErrorMessage(`ERROR: ${e.message} (${e.errorCode})`)
|
setErrorMessage(`ERROR: ${e.message} (${e.errorCode})`)
|
||||||
}
|
}
|
||||||
else if (e instanceof Error) {
|
else if (e instanceof Error) {
|
||||||
|
|
|
||||||
|
|
@ -4,14 +4,10 @@ import {
|
||||||
Flex,
|
Flex,
|
||||||
Modal,
|
Modal,
|
||||||
Stack,
|
Stack,
|
||||||
Switch,
|
|
||||||
TextInput,
|
TextInput,
|
||||||
Textarea,
|
|
||||||
Button,
|
Button,
|
||||||
ScrollArea,
|
ScrollArea,
|
||||||
Checkbox,
|
|
||||||
Skeleton,
|
Skeleton,
|
||||||
Fieldset,
|
|
||||||
Alert,
|
Alert,
|
||||||
Center,
|
Center,
|
||||||
Avatar,
|
Avatar,
|
||||||
|
|
@ -20,7 +16,7 @@ import {
|
||||||
} from "@mantine/core";
|
} from "@mantine/core";
|
||||||
import { useForm, zodResolver } from "@mantine/form";
|
import { useForm, zodResolver } from "@mantine/form";
|
||||||
import { useRouter } from "next/navigation";
|
import { useRouter } from "next/navigation";
|
||||||
import React, { useCallback, useEffect, useState } from "react";
|
import React, { useEffect, useState } from "react";
|
||||||
import { TbDeviceFloppy } from "react-icons/tb";
|
import { TbDeviceFloppy } from "react-icons/tb";
|
||||||
import userFormDataSchema, {
|
import userFormDataSchema, {
|
||||||
UserFormData,
|
UserFormData,
|
||||||
|
|
@ -28,7 +24,7 @@ import userFormDataSchema, {
|
||||||
import getUserDetailById from "../actions/getUserDetailById";
|
import getUserDetailById from "../actions/getUserDetailById";
|
||||||
import withServerAction from "@/modules/dashboard/utils/withServerAction";
|
import withServerAction from "@/modules/dashboard/utils/withServerAction";
|
||||||
import upsertUser from "../actions/upsertUser";
|
import upsertUser from "../actions/upsertUser";
|
||||||
import DashboardError from "@/modules/dashboard/errors/DashboardError";
|
import ClientError from "@/core/error/ClientError";
|
||||||
import stringToColorHex from "@/core/utils/stringToColorHex";
|
import stringToColorHex from "@/core/utils/stringToColorHex";
|
||||||
import getAllRoles from "@/modules/role/actions/getAllRoles";
|
import getAllRoles from "@/modules/role/actions/getAllRoles";
|
||||||
import Role from "@/modules/role/types/Role";
|
import Role from "@/modules/role/types/Role";
|
||||||
|
|
@ -122,7 +118,7 @@ export default function UserFormModal(props: ModalProps) {
|
||||||
closeModal();
|
closeModal();
|
||||||
})
|
})
|
||||||
.catch((e) => {
|
.catch((e) => {
|
||||||
if (e instanceof DashboardError) {
|
if (e instanceof ClientError) {
|
||||||
if (e.errorCode === "INVALID_FORM_DATA") {
|
if (e.errorCode === "INVALID_FORM_DATA") {
|
||||||
form.setErrors(e.formErrors ?? {});
|
form.setErrors(e.formErrors ?? {});
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user