new features
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
|
||||
import { useState } from "react";
|
||||
import { useForm, SubmitHandler } from "react-hook-form";
|
||||
import { useTranslations } from "next-intl";
|
||||
import { useLocale, useTranslations } from "next-intl";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Dialog, DialogClose, DialogContent, DialogFooter, DialogHeader, DialogTitle, DialogTrigger } from "@/components/ui/dialog";
|
||||
import { Input } from "@/components/ui/input";
|
||||
@@ -35,6 +35,7 @@ interface FormData {
|
||||
|
||||
export function PermissionDialog(props: Props) {
|
||||
const t = useTranslations("MePage.items.admin.permissions")
|
||||
const locale = useLocale()
|
||||
const isEdit = props.mode === "edit"
|
||||
|
||||
const [open, setOpen] = useState(false)
|
||||
@@ -49,8 +50,8 @@ export function PermissionDialog(props: Props) {
|
||||
|
||||
const onSubmit: SubmitHandler<FormData> = async (data) => {
|
||||
const result = isEdit
|
||||
? await editPermission((props as EditProps).permission.code, data.description || undefined)
|
||||
: await addPermission(data.code, data.description || undefined)
|
||||
? await editPermission((props as EditProps).permission.code, data.description || undefined, locale)
|
||||
: await addPermission(data.code, data.description || undefined, locale)
|
||||
|
||||
if (!result.success) {
|
||||
toast(isEdit ? t("edit.error") : t("create.error"), { icon: <X size={16} /> })
|
||||
@@ -59,7 +60,7 @@ export function PermissionDialog(props: Props) {
|
||||
|
||||
const updated: Permission = isEdit
|
||||
? { ...(props as EditProps).permission, description: data.description }
|
||||
: { id: crypto.randomUUID(), code: data.code, description: data.description, created_at: new Date().toISOString() }
|
||||
: { id: crypto.randomUUID(), code: data.code, name: data.code, description: data.description, created_at: new Date().toISOString() }
|
||||
|
||||
toast(isEdit ? t("edit.success") : t("create.success"), { icon: <Check size={16} /> })
|
||||
props.onSuccess(updated)
|
||||
|
||||
Reference in New Issue
Block a user