refactor: improve code formatting and readability in settings component by adjusting indentation and line breaks
This commit is contained in:
parent
96ad0de44c
commit
c07f1bd3bb
@ -1,8 +1,8 @@
|
|||||||
import { Button } from '@/components/ui/button';
|
import { Button } from '@/components/ui/button';
|
||||||
import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card';
|
import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card';
|
||||||
import { Field, FieldError } from "@/components/ui/field";
|
import { Field, FieldError } from '@/components/ui/field';
|
||||||
import { Input } from "@/components/ui/input";
|
import { Input } from '@/components/ui/input';
|
||||||
import { Label } from "@/components/ui/label";
|
import { Label } from '@/components/ui/label';
|
||||||
import { Textarea } from '@/components/ui/textarea';
|
import { Textarea } from '@/components/ui/textarea';
|
||||||
import systemRoutes from '@/routes/system';
|
import systemRoutes from '@/routes/system';
|
||||||
import type { GeneralSetting } from '@/types';
|
import type { GeneralSetting } from '@/types';
|
||||||
@ -11,7 +11,11 @@ import { ImagePlus, Loader, Save, X } from 'lucide-react';
|
|||||||
import React, { useRef, useState } from 'react';
|
import React, { useRef, useState } from 'react';
|
||||||
import { toast } from 'sonner';
|
import { toast } from 'sonner';
|
||||||
|
|
||||||
export default function SettingIndex({ setting }: { setting: GeneralSetting | null }) {
|
export default function SettingIndex({
|
||||||
|
setting,
|
||||||
|
}: {
|
||||||
|
setting: GeneralSetting | null;
|
||||||
|
}) {
|
||||||
const { data, setData, post, processing, errors } = useForm({
|
const { data, setData, post, processing, errors } = useForm({
|
||||||
name: setting?.name || '',
|
name: setting?.name || '',
|
||||||
description: setting?.description || '',
|
description: setting?.description || '',
|
||||||
@ -24,8 +28,12 @@ export default function SettingIndex({ setting }: { setting: GeneralSetting | nu
|
|||||||
const logoInputRef = useRef<HTMLInputElement>(null);
|
const logoInputRef = useRef<HTMLInputElement>(null);
|
||||||
const iconInputRef = useRef<HTMLInputElement>(null);
|
const iconInputRef = useRef<HTMLInputElement>(null);
|
||||||
|
|
||||||
const [logoPreview, setLogoPreview] = useState<string | null>(setting?.logo_url || null);
|
const [logoPreview, setLogoPreview] = useState<string | null>(
|
||||||
const [iconPreview, setIconPreview] = useState<string | null>(setting?.icon_url || null);
|
setting?.logo_url || null,
|
||||||
|
);
|
||||||
|
const [iconPreview, setIconPreview] = useState<string | null>(
|
||||||
|
setting?.icon_url || null,
|
||||||
|
);
|
||||||
|
|
||||||
const handleLogoChange = (e: React.ChangeEvent<HTMLInputElement>) => {
|
const handleLogoChange = (e: React.ChangeEvent<HTMLInputElement>) => {
|
||||||
const file = e.target.files?.[0];
|
const file = e.target.files?.[0];
|
||||||
@ -87,74 +95,111 @@ export default function SettingIndex({ setting }: { setting: GeneralSetting | nu
|
|||||||
|
|
||||||
<div className="flex items-center justify-between">
|
<div className="flex items-center justify-between">
|
||||||
<div>
|
<div>
|
||||||
<h1 className="text-3xl font-bold tracking-tight">Pengaturan Umum</h1>
|
<h1 className="text-3xl font-bold tracking-tight">
|
||||||
|
Pengaturan Umum
|
||||||
|
</h1>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<form onSubmit={onSubmit} className="space-y-6">
|
<form onSubmit={onSubmit} className="space-y-6">
|
||||||
<div className="grid grid-cols-1 lg:grid-cols-3 gap-6">
|
<div className="grid grid-cols-1 gap-6 lg:grid-cols-3">
|
||||||
<div className="lg:col-span-2 space-y-6">
|
<div className="space-y-6 lg:col-span-2">
|
||||||
<Card className="overflow-hidden border-none shadow-lg bg-card/50 backdrop-blur-sm">
|
<Card className="overflow-hidden border-none bg-card/50 shadow-lg backdrop-blur-sm">
|
||||||
<CardHeader className="border-b">
|
<CardHeader className="border-b">
|
||||||
<CardTitle>Informasi Aplikasi</CardTitle>
|
<CardTitle>Informasi Aplikasi</CardTitle>
|
||||||
</CardHeader>
|
</CardHeader>
|
||||||
<CardContent className="space-y-6">
|
<CardContent className="space-y-6">
|
||||||
<div className="grid grid-cols-1 md:grid-cols-2 gap-6">
|
<div className="grid grid-cols-1 gap-6 md:grid-cols-2">
|
||||||
<Field>
|
<Field>
|
||||||
<Label htmlFor="phone" required>No. Telepon</Label>
|
<Label htmlFor="phone" required>
|
||||||
|
No. Telepon
|
||||||
|
</Label>
|
||||||
<Input
|
<Input
|
||||||
id="phone"
|
id="phone"
|
||||||
value={data.phone || ''}
|
value={data.phone || ''}
|
||||||
onChange={(e) => setData('phone', e.target.value)}
|
onChange={(e) =>
|
||||||
|
setData('phone', e.target.value)
|
||||||
|
}
|
||||||
placeholder="0812xxxx"
|
placeholder="0812xxxx"
|
||||||
/>
|
/>
|
||||||
<FieldError error={errors.phone} label="No. Telepon" className="text-xs" />
|
<FieldError
|
||||||
|
error={errors.phone}
|
||||||
|
label="No. Telepon"
|
||||||
|
className="text-xs"
|
||||||
|
/>
|
||||||
</Field>
|
</Field>
|
||||||
|
|
||||||
<Field>
|
<Field>
|
||||||
<Label htmlFor="name" required>Nama Aplikasi</Label>
|
<Label htmlFor="name" required>
|
||||||
|
Nama Aplikasi
|
||||||
|
</Label>
|
||||||
<Input
|
<Input
|
||||||
id="name"
|
id="name"
|
||||||
name="name"
|
name="name"
|
||||||
value={data.name}
|
value={data.name}
|
||||||
onChange={e => setData('name', e.target.value)}
|
onChange={(e) =>
|
||||||
autoComplete='off'
|
setData('name', e.target.value)
|
||||||
placeholder='Contoh: VN Grup Dress'
|
}
|
||||||
|
autoComplete="off"
|
||||||
|
placeholder="Contoh: VN Grup Dress"
|
||||||
maxLength={100}
|
maxLength={100}
|
||||||
/>
|
/>
|
||||||
<FieldError error={errors.name} label="Nama Aplikasi" className="text-xs" />
|
<FieldError
|
||||||
|
error={errors.name}
|
||||||
|
label="Nama Aplikasi"
|
||||||
|
className="text-xs"
|
||||||
|
/>
|
||||||
</Field>
|
</Field>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<Field>
|
<Field>
|
||||||
<Label htmlFor="description" required>Deskripsi</Label>
|
<Label htmlFor="description" required>
|
||||||
|
Deskripsi
|
||||||
|
</Label>
|
||||||
<Textarea
|
<Textarea
|
||||||
id="description"
|
id="description"
|
||||||
value={data.description || ''}
|
value={data.description || ''}
|
||||||
onChange={(e) => setData('description', e.target.value)}
|
onChange={(e) =>
|
||||||
|
setData(
|
||||||
|
'description',
|
||||||
|
e.target.value,
|
||||||
|
)
|
||||||
|
}
|
||||||
placeholder="Deskripsi singkat aplikasi"
|
placeholder="Deskripsi singkat aplikasi"
|
||||||
rows={4}
|
rows={4}
|
||||||
/>
|
/>
|
||||||
<FieldError error={errors.description} label="Deskripsi" className="text-xs mt-1" />
|
<FieldError
|
||||||
|
error={errors.description}
|
||||||
|
label="Deskripsi"
|
||||||
|
className="mt-1 text-xs"
|
||||||
|
/>
|
||||||
</Field>
|
</Field>
|
||||||
|
|
||||||
<Field>
|
<Field>
|
||||||
<Label htmlFor="address" required>Alamat</Label>
|
<Label htmlFor="address" required>
|
||||||
|
Alamat
|
||||||
|
</Label>
|
||||||
<Textarea
|
<Textarea
|
||||||
id="address"
|
id="address"
|
||||||
value={data.address || ''}
|
value={data.address || ''}
|
||||||
onChange={(e) => setData('address', e.target.value)}
|
onChange={(e) =>
|
||||||
|
setData('address', e.target.value)
|
||||||
|
}
|
||||||
placeholder="Alamat lengkap toko"
|
placeholder="Alamat lengkap toko"
|
||||||
rows={3}
|
rows={3}
|
||||||
/>
|
/>
|
||||||
<FieldError error={errors.address} label="Alamat" className="text-xs mt-1" />
|
<FieldError
|
||||||
|
error={errors.address}
|
||||||
|
label="Alamat"
|
||||||
|
className="mt-1 text-xs"
|
||||||
|
/>
|
||||||
</Field>
|
</Field>
|
||||||
</CardContent>
|
</CardContent>
|
||||||
</Card>
|
</Card>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="space-y-6">
|
<div className="space-y-6">
|
||||||
<Card className="overflow-hidden border-none shadow-lg bg-card/50 backdrop-blur-sm">
|
<Card className="overflow-hidden border-none bg-card/50 shadow-lg backdrop-blur-sm">
|
||||||
<CardHeader className="border-b">
|
<CardHeader className="border-b">
|
||||||
<CardTitle>Logo Aplikasi</CardTitle>
|
<CardTitle>Logo Aplikasi</CardTitle>
|
||||||
</CardHeader>
|
</CardHeader>
|
||||||
@ -164,25 +209,31 @@ export default function SettingIndex({ setting }: { setting: GeneralSetting | nu
|
|||||||
<img
|
<img
|
||||||
src={logoPreview}
|
src={logoPreview}
|
||||||
alt="Logo preview"
|
alt="Logo preview"
|
||||||
className="w-full object-cover rounded-xl border shadow"
|
className="w-full rounded-xl border object-cover shadow"
|
||||||
/>
|
/>
|
||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
onClick={removeLogo}
|
onClick={removeLogo}
|
||||||
className="absolute -top-2 -right-2 bg-red-500 hover:bg-red-600 text-white rounded-full w-6 h-6 flex items-center justify-center shadow-md transition-colors"
|
className="absolute -top-2 -right-2 flex h-6 w-6 items-center justify-center rounded-full bg-red-500 text-white shadow-md transition-colors hover:bg-red-600"
|
||||||
>
|
>
|
||||||
<X className="w-3.5 h-3.5" />
|
<X className="h-3.5 w-3.5" />
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
) : (
|
) : (
|
||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
onClick={() => logoInputRef.current?.click()}
|
onClick={() =>
|
||||||
className="flex flex-col items-center justify-center w-full h-40 border-2 border-dashed border-border rounded-xl hover:border-primary hover:bg-primary/5 transition-all cursor-pointer group"
|
logoInputRef.current?.click()
|
||||||
|
}
|
||||||
|
className="group flex h-40 w-full cursor-pointer flex-col items-center justify-center rounded-xl border-2 border-dashed border-border transition-all hover:border-primary hover:bg-primary/5"
|
||||||
>
|
>
|
||||||
<ImagePlus className="w-10 h-10 text-muted-foreground group-hover:text-primary transition-colors mb-2" />
|
<ImagePlus className="mb-2 h-10 w-10 text-muted-foreground transition-colors group-hover:text-primary" />
|
||||||
<span className="text-sm text-muted-foreground group-hover:text-primary transition-colors font-medium">Klik untuk upload logo</span>
|
<span className="text-sm font-medium text-muted-foreground transition-colors group-hover:text-primary">
|
||||||
<span className="text-xs text-muted-foreground mt-1">PNG, JPG, WEBP — maks. 2MB</span>
|
Klik untuk upload logo
|
||||||
|
</span>
|
||||||
|
<span className="mt-1 text-xs text-muted-foreground">
|
||||||
|
PNG, JPG, WEBP — maks. 2MB
|
||||||
|
</span>
|
||||||
</button>
|
</button>
|
||||||
)}
|
)}
|
||||||
<input
|
<input
|
||||||
@ -192,41 +243,51 @@ export default function SettingIndex({ setting }: { setting: GeneralSetting | nu
|
|||||||
className="hidden"
|
className="hidden"
|
||||||
onChange={handleLogoChange}
|
onChange={handleLogoChange}
|
||||||
/>
|
/>
|
||||||
<FieldError error={errors.logo} label="Logo Aplikasi" className="text-xs mt-2" />
|
<FieldError
|
||||||
|
error={errors.logo}
|
||||||
|
label="Logo Aplikasi"
|
||||||
|
className="mt-2 text-xs"
|
||||||
|
/>
|
||||||
</CardContent>
|
</CardContent>
|
||||||
</Card>
|
</Card>
|
||||||
|
|
||||||
<Card className="overflow-hidden border-none shadow-lg bg-card/50 backdrop-blur-sm">
|
<Card className="overflow-hidden border-none bg-card/50 shadow-lg backdrop-blur-sm">
|
||||||
<CardHeader className="border-b">
|
<CardHeader className="border-b">
|
||||||
<CardTitle>Favicon / Icon</CardTitle>
|
<CardTitle>Favicon / Icon</CardTitle>
|
||||||
</CardHeader>
|
</CardHeader>
|
||||||
<CardContent>
|
<CardContent>
|
||||||
{iconPreview ? (
|
{iconPreview ? (
|
||||||
<div className="relative inline-block w-full flex justify-center">
|
<div className="relative flex inline-block w-full justify-center">
|
||||||
<div className="relative">
|
<div className="relative">
|
||||||
<img
|
<img
|
||||||
src={iconPreview}
|
src={iconPreview}
|
||||||
alt="Icon preview"
|
alt="Icon preview"
|
||||||
className="size-24 object-contain rounded-xl border shadow p-2"
|
className="size-24 rounded-xl border object-contain p-2 shadow"
|
||||||
/>
|
/>
|
||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
onClick={removeIcon}
|
onClick={removeIcon}
|
||||||
className="absolute -top-2 -right-2 bg-red-500 hover:bg-red-600 text-white rounded-full w-6 h-6 flex items-center justify-center shadow-md transition-colors"
|
className="absolute -top-2 -right-2 flex h-6 w-6 items-center justify-center rounded-full bg-red-500 text-white shadow-md transition-colors hover:bg-red-600"
|
||||||
>
|
>
|
||||||
<X className="w-3.5 h-3.5" />
|
<X className="h-3.5 w-3.5" />
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
) : (
|
) : (
|
||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
onClick={() => iconInputRef.current?.click()}
|
onClick={() =>
|
||||||
className="flex flex-col items-center justify-center w-full h-32 border-2 border-dashed border-border rounded-xl hover:border-primary hover:bg-primary/5 transition-all cursor-pointer group"
|
iconInputRef.current?.click()
|
||||||
|
}
|
||||||
|
className="group flex h-32 w-full cursor-pointer flex-col items-center justify-center rounded-xl border-2 border-dashed border-border transition-all hover:border-primary hover:bg-primary/5"
|
||||||
>
|
>
|
||||||
<ImagePlus className="w-8 h-8 text-muted-foreground group-hover:text-primary transition-colors mb-2" />
|
<ImagePlus className="mb-2 h-8 w-8 text-muted-foreground transition-colors group-hover:text-primary" />
|
||||||
<span className="text-sm text-muted-foreground group-hover:text-primary transition-colors font-medium">Klik untuk upload icon</span>
|
<span className="text-sm font-medium text-muted-foreground transition-colors group-hover:text-primary">
|
||||||
<span className="text-xs text-muted-foreground mt-1">ICO, PNG — maks. 1MB</span>
|
Klik untuk upload icon
|
||||||
|
</span>
|
||||||
|
<span className="mt-1 text-xs text-muted-foreground">
|
||||||
|
ICO, PNG — maks. 1MB
|
||||||
|
</span>
|
||||||
</button>
|
</button>
|
||||||
)}
|
)}
|
||||||
<input
|
<input
|
||||||
@ -236,18 +297,24 @@ export default function SettingIndex({ setting }: { setting: GeneralSetting | nu
|
|||||||
className="hidden"
|
className="hidden"
|
||||||
onChange={handleIconChange}
|
onChange={handleIconChange}
|
||||||
/>
|
/>
|
||||||
<FieldError error={errors.icon} label="Favicon / Icon" className="text-xs mt-2" />
|
<FieldError
|
||||||
|
error={errors.icon}
|
||||||
|
label="Favicon / Icon"
|
||||||
|
className="mt-2 text-xs"
|
||||||
|
/>
|
||||||
</CardContent>
|
</CardContent>
|
||||||
</Card>
|
</Card>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div className="flex flex-col gap-4 p-4 rounded-xl bg-primary/5 border border-primary/10 shadow-sm">
|
<Button type="submit" disabled={processing}>
|
||||||
<Button type="submit" className="w-full gap-2" disabled={processing}>
|
{processing ? (
|
||||||
{processing ? <Loader className="size-4 animate-spin" /> : <Save className="size-4" />}
|
<Loader className="size-4 animate-spin" />
|
||||||
|
) : (
|
||||||
|
<Save className="size-4" />
|
||||||
|
)}
|
||||||
{processing ? 'Menyimpan...' : 'Simpan'}
|
{processing ? 'Menyimpan...' : 'Simpan'}
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
@ -257,6 +324,6 @@ SettingIndex.layout = {
|
|||||||
breadcrumbs: [
|
breadcrumbs: [
|
||||||
{
|
{
|
||||||
title: 'Sistem',
|
title: 'Sistem',
|
||||||
}
|
},
|
||||||
],
|
],
|
||||||
};
|
};
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user