fix: 🚸 improve model title slugify button
This commit is contained in:
parent
1af57f02b3
commit
2055ec91fd
2 changed files with 74 additions and 78 deletions
|
|
@ -1,6 +1,6 @@
|
|||
// * Packages
|
||||
import { useForm, usePage } from "@inertiajs/react";
|
||||
import { BookTextIcon, CogIcon, EyeIcon, ShieldAlertIcon } from "lucide-react";
|
||||
import { BookTextIcon, CogIcon, EyeIcon, GavelIcon, ShieldAlertIcon } from "lucide-react";
|
||||
import { route } from "ziggy-js";
|
||||
import { FormEvent, useEffect, useState } from "react";
|
||||
// * Components shadcn
|
||||
|
|
@ -303,23 +303,35 @@ export default function Form({
|
|||
setData={setData}
|
||||
onSelectValue={(value) => setSelectedGroup(value)}
|
||||
/>
|
||||
<SimpleString
|
||||
name="slug"
|
||||
label={str(
|
||||
useTrans("back.form_associate_to", {
|
||||
params: {
|
||||
attribute: useTrans("validation.custom.slug"),
|
||||
},
|
||||
choice: 1,
|
||||
}),
|
||||
)
|
||||
.ucFirst()
|
||||
.value()}
|
||||
wordCounter={false}
|
||||
value={data.slug}
|
||||
pattern="[a-z0-9\-]{3,255}"
|
||||
setData={setData}
|
||||
/>
|
||||
<div className="flex items-end gap-1">
|
||||
<SimpleString
|
||||
name="slug"
|
||||
label={str(
|
||||
useTrans("back.form_associate_to", {
|
||||
params: {
|
||||
attribute: useTrans("validation.custom.slug"),
|
||||
},
|
||||
choice: 1,
|
||||
}),
|
||||
)
|
||||
.ucFirst()
|
||||
.value()}
|
||||
wordCounter={false}
|
||||
value={data.slug}
|
||||
pattern="[a-z0-9\-]{3,255}"
|
||||
setData={setData}
|
||||
/>
|
||||
<BtnOptionnalLinkWithTooltip
|
||||
content={<GavelIcon className="w-4 h-4 m-auto" />}
|
||||
tooltipContent={str(useTrans('back.slugify')).ucFirst().value()}
|
||||
type="button"
|
||||
variant="secondary"
|
||||
onClick={() => {
|
||||
console.log("test");
|
||||
setData("slug", str(data.title).slug().value());
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
<div className="col-span-1 md:col-span-2">
|
||||
<GoToFrontView
|
||||
model={model}
|
||||
|
|
|
|||
|
|
@ -1,32 +1,32 @@
|
|||
// * Packages
|
||||
import { useForm, usePage } from "@inertiajs/react";
|
||||
import { BookText, Cog, RefreshCw } from "lucide-react";
|
||||
import { BookTextIcon, CogIcon, RefreshCwIcon, GavelIcon } from "lucide-react";
|
||||
import { route } from "ziggy-js";
|
||||
import { FormEvent, useState } from "react";
|
||||
import { FormEvent, useEffect, useState } from "react";
|
||||
// * Components shadcn
|
||||
import { Separator } from "@/components/ui/separator";
|
||||
import { Skeleton } from "@/components/ui/skeleton";
|
||||
import { Card, CardContent } from "@/components/ui/card";
|
||||
// * Other
|
||||
import SimpleString from "@/back/Components/Inputs/SimpleString";
|
||||
import FieldsetWrapper from "@/back/Components/FieldsetWrapper";
|
||||
import BtnOptionnalLinkWithTooltip from "@/back/Components/BtnOptionnalLinkWithTooltip";
|
||||
import useTrans from "@/hooks/use-translations";
|
||||
import str from "@/hooks/use-string";
|
||||
import InputError from "@/back/Components/InputError";
|
||||
import { useToast } from "@/hooks/use-toast";
|
||||
import { Methods } from "@/lib/enums";
|
||||
import { AppEnv, DynamicFieldTypes, LaravelEnum, NewsModel } from "@/back/types/global";
|
||||
import GoToFrontView from "@/back/Components/GoToFrontView";
|
||||
import SimpleString from "@/back/Components/Inputs/SimpleString";
|
||||
import EnumSelect from "@/back/Components/Inputs/EnumSelect";
|
||||
import SimpleWysiwyg from "@/back/Components/Inputs/SimpleWysiwyg";
|
||||
import { MultiSelect } from "@/back/Components/Inputs/MultiSelect";
|
||||
import SimpleDatePicker from "@/back/Components/Inputs/SimpleDatePicker";
|
||||
import { mapLaravelEnumOptions } from "@/lib/mapEnumOptions";
|
||||
import ImageCropperWrapper from "@/back/Components/Inputs/CompleteInputFile";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import GoToFrontView from "@/back/Components/GoToFrontView";
|
||||
import CompleteInputFile from "@/back/Components/Inputs/CompleteInputFile";
|
||||
import SimpleSwitch from "@/back/Components/Inputs/SimpleSwitch";
|
||||
import { Skeleton } from "@/components/ui/skeleton";
|
||||
import { cn } from "@/lib/utils";
|
||||
import { Card, CardContent } from "@/components/ui/card";
|
||||
import SimpleVimeoId from "@/back/Components/Inputs/SimpleVimeoId";
|
||||
import { Separator } from "@/components/ui/separator";
|
||||
import { mapLaravelEnumOptions } from "@/lib/mapEnumOptions";
|
||||
import { cn } from "@/lib/utils";
|
||||
import { Methods } from "@/lib/enums";
|
||||
import { AppEnv, DynamicFieldTypes, LaravelEnum, NewsModel } from "@/back/types/global";
|
||||
import { useToast } from "@/hooks/use-toast";
|
||||
import useTrans from "@/hooks/use-translations";
|
||||
import str from "@/hooks/use-string";
|
||||
|
||||
export default function Form({
|
||||
model,
|
||||
|
|
@ -43,21 +43,13 @@ export default function Form({
|
|||
}) {
|
||||
const { locale } = usePage().props.appEnv as AppEnv;
|
||||
const { toast } = useToast();
|
||||
const [isGif, setIsGif] = useState(() => {
|
||||
if (model?.picture && typeof model.picture === "string") {
|
||||
return model.picture.toLowerCase().endsWith(".gif");
|
||||
}
|
||||
if (isFile(data.picture)) {
|
||||
return data.picture.name.toLowerCase().endsWith(".gif");
|
||||
}
|
||||
return false;
|
||||
});
|
||||
|
||||
const [isGif, setIsGif] = useState<boolean>(false);
|
||||
const [dynamicKey, setDynamicKey] = useState<number | null>(null);
|
||||
const enumDynamicFieldTypes = usePage().props.enumDynamicFieldTypes as DynamicFieldTypes;
|
||||
const enumNewsStatus = usePage().props.enumNewsStatus as LaravelEnum;
|
||||
const enumNewsCategory = usePage().props.enumNewsCategory as LaravelEnum;
|
||||
const { options, defaultValue } = mapLaravelEnumOptions(enumNewsCategory, model?.categories, "category");
|
||||
|
||||
/** Set messages success/errors */
|
||||
const messages = {} as Record<string, string>;
|
||||
messages.titleSuccess = useTrans(
|
||||
|
|
@ -103,7 +95,6 @@ export default function Form({
|
|||
unpublished_at: model?.unpublished_at ? model?.unpublished_at : null
|
||||
});
|
||||
|
||||
|
||||
const refreshFileFromDb = () => {
|
||||
if (model && model.picture) {
|
||||
const isGif = typeof model.picture === "string" && model.picture.toLowerCase().endsWith(".gif");
|
||||
|
|
@ -152,27 +143,24 @@ export default function Form({
|
|||
)
|
||||
}
|
||||
|
||||
|
||||
|
||||
const SlugiFyButton = () => {
|
||||
return (
|
||||
<Button variant={"secondary"} type="button" onClick={() => setData("slug", str(data.title).slug().value())}>
|
||||
<RefreshCw />
|
||||
{str(useTrans('back.slugify')).ucFirst().value()}
|
||||
</Button>
|
||||
);
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
useEffect(() => {
|
||||
setIsGif(() => {
|
||||
if (model && model?.picture && typeof model.picture === "string") {
|
||||
return model.picture.toLowerCase().endsWith(".gif");
|
||||
}
|
||||
if (isFile(data.picture)) {
|
||||
return data.picture.name.toLowerCase().endsWith(".gif");
|
||||
}
|
||||
return false;
|
||||
});
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<form onSubmit={submit}>
|
||||
<InputError all />
|
||||
<FieldsetWrapper
|
||||
title={useTrans("back.form_title_seo")}
|
||||
icon={<BookText className="mr-1" />}
|
||||
icon={<BookTextIcon className="mr-1" />}
|
||||
description={useTrans("back.form_subtitle_seo")}
|
||||
className="sm:grid-cols-2 gap-4"
|
||||
>
|
||||
|
|
@ -209,7 +197,7 @@ export default function Form({
|
|||
</FieldsetWrapper>
|
||||
<FieldsetWrapper
|
||||
title={useTrans("back.form_title_global")}
|
||||
icon={<BookText className="mr-1" />}
|
||||
icon={<BookTextIcon className="mr-1" />}
|
||||
description={useTrans("back.form_subtitle_global")}
|
||||
className="space-y-3"
|
||||
>
|
||||
|
|
@ -243,7 +231,13 @@ export default function Form({
|
|||
value={data.slug}
|
||||
setData={setData}
|
||||
/>
|
||||
<SlugiFyButton />
|
||||
<BtnOptionnalLinkWithTooltip
|
||||
content={<GavelIcon className="w-4 h-4 m-auto" />}
|
||||
tooltipContent={str(useTrans('back.slugify')).ucFirst().value()}
|
||||
type="button"
|
||||
variant="secondary"
|
||||
onClick={() => setData("slug", str(data.title).slug().value())}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
<GoToFrontView
|
||||
|
|
@ -256,7 +250,7 @@ export default function Form({
|
|||
</FieldsetWrapper>
|
||||
<FieldsetWrapper
|
||||
title={useTrans("back.form_title_configuration")}
|
||||
icon={<Cog className="mr-1" />}
|
||||
icon={<CogIcon className="mr-1" />}
|
||||
description={useTrans("back.form_subtitle_configuration")}
|
||||
className="sm:grid-cols-2 gap-4"
|
||||
>
|
||||
|
|
@ -306,7 +300,7 @@ export default function Form({
|
|||
</FieldsetWrapper>
|
||||
<FieldsetWrapper
|
||||
title={useTrans("back.form_title_display")}
|
||||
icon={<BookText className="mr-1" />}
|
||||
icon={<BookTextIcon className="mr-1" />}
|
||||
description={useTrans("back.form_subtitle_display")}
|
||||
className="sm:grid-cols-2 gap-4"
|
||||
>
|
||||
|
|
@ -340,20 +334,13 @@ export default function Form({
|
|||
<Skeleton className="h-5 w-[95%]" />
|
||||
<Skeleton className="h-5 w-[79%]" />
|
||||
</div>
|
||||
|
||||
{/* <div className={cn('space-y-2', data.inverted ? 'order-1' : 'order-2')}>
|
||||
<Skeleton className="h-4 w-[250px]" />
|
||||
<Skeleton className="h-4 w-[200px]" />
|
||||
<Skeleton className="h-4 w-[300px]" />
|
||||
<Skeleton className="h-4 w-[290px]" />
|
||||
</div> */}
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
</FieldsetWrapper>
|
||||
<FieldsetWrapper
|
||||
title={useTrans("back.form_title_content")}
|
||||
icon={<BookText className="mr-1" />}
|
||||
icon={<BookTextIcon className="mr-1" />}
|
||||
description={useTrans("back.form_subtitle_content")}
|
||||
className="gap-4"
|
||||
>
|
||||
|
|
@ -376,13 +363,12 @@ export default function Form({
|
|||
setDynamicKey(Date.now());
|
||||
}}
|
||||
/>
|
||||
|
||||
{model && model.picture && (
|
||||
<BtnOptionnalLinkWithTooltip
|
||||
variant={'secondary'}
|
||||
onClick={refreshFileFromDb}
|
||||
content={
|
||||
<RefreshCw />
|
||||
<RefreshCwIcon />
|
||||
}
|
||||
tooltipContent="Remettre à l'état d'origine"
|
||||
/>
|
||||
|
|
@ -390,7 +376,7 @@ export default function Form({
|
|||
</div>
|
||||
</div>
|
||||
<div className="grid sm:grid-cols-2 gap-4 col-span-2 gap-4">
|
||||
<ImageCropperWrapper
|
||||
<CompleteInputFile
|
||||
key={dynamicKey}
|
||||
fileName="picture"
|
||||
modelRoute="news"
|
||||
|
|
@ -415,9 +401,7 @@ export default function Form({
|
|||
}}
|
||||
inputType={isGif ? enumDynamicFieldTypes.file.value : enumDynamicFieldTypes.image.value}
|
||||
/>
|
||||
<div></div>
|
||||
</div>
|
||||
|
||||
<div className="grid sm:grid-cols-2 col-span-2 gap-4">
|
||||
<SimpleString
|
||||
name="picture_alt"
|
||||
|
|
@ -488,7 +472,7 @@ export default function Form({
|
|||
</FieldsetWrapper>
|
||||
<FieldsetWrapper
|
||||
title={useTrans("back.form_title_additional_files")}
|
||||
icon={<BookText className="mr-1" />}
|
||||
icon={<BookTextIcon className="mr-1" />}
|
||||
description={useTrans("back.form_subtitle_additional_files")}
|
||||
className="sm:grid-cols-2 gap-4"
|
||||
>
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue