feat: add slug field to profile section edit modal and update service DTO
This commit is contained in:
@@ -27,9 +27,10 @@ export default function ProfileSectionsPage() {
|
|||||||
const [isSubmitting, setIsSubmitting] = useState(false);
|
const [isSubmitting, setIsSubmitting] = useState(false);
|
||||||
const [modalError, setModalError] = useState('');
|
const [modalError, setModalError] = useState('');
|
||||||
|
|
||||||
// Form state
|
// Form state (slug is only editable in the edit modal)
|
||||||
const [formData, setFormData] = useState<CreateSectionDto>({
|
const [formData, setFormData] = useState<CreateSectionDto & { slug?: string }>({
|
||||||
name: '',
|
name: '',
|
||||||
|
slug: '',
|
||||||
description: '',
|
description: '',
|
||||||
icon: '',
|
icon: '',
|
||||||
isActive: true,
|
isActive: true,
|
||||||
@@ -62,6 +63,7 @@ export default function ProfileSectionsPage() {
|
|||||||
const openCreateModal = () => {
|
const openCreateModal = () => {
|
||||||
setFormData({
|
setFormData({
|
||||||
name: '',
|
name: '',
|
||||||
|
slug: '',
|
||||||
description: '',
|
description: '',
|
||||||
icon: '',
|
icon: '',
|
||||||
isActive: true,
|
isActive: true,
|
||||||
@@ -77,6 +79,7 @@ export default function ProfileSectionsPage() {
|
|||||||
setSelectedSection(section);
|
setSelectedSection(section);
|
||||||
setFormData({
|
setFormData({
|
||||||
name: section.name,
|
name: section.name,
|
||||||
|
slug: section.slug,
|
||||||
description: section.description || '',
|
description: section.description || '',
|
||||||
icon: section.icon || '',
|
icon: section.icon || '',
|
||||||
isActive: section.isActive,
|
isActive: section.isActive,
|
||||||
@@ -105,7 +108,10 @@ export default function ProfileSectionsPage() {
|
|||||||
setIsSubmitting(true);
|
setIsSubmitting(true);
|
||||||
setModalError('');
|
setModalError('');
|
||||||
try {
|
try {
|
||||||
await profileSectionsService.create(formData);
|
// Backend auto-generates slug on create; don't send the form slug field
|
||||||
|
const { slug: _slug, ...createPayload } = formData;
|
||||||
|
void _slug;
|
||||||
|
await profileSectionsService.create(createPayload);
|
||||||
closeModal();
|
closeModal();
|
||||||
fetchSections();
|
fetchSections();
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
@@ -410,6 +416,26 @@ export default function ProfileSectionsPage() {
|
|||||||
required
|
required
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
{modalType === 'edit' && (
|
||||||
|
<div>
|
||||||
|
<label className="block text-sm font-medium text-[#00293d] mb-1">
|
||||||
|
Slug <span className="text-red-500">*</span>
|
||||||
|
</label>
|
||||||
|
<input
|
||||||
|
type="text"
|
||||||
|
value={formData.slug || ''}
|
||||||
|
onChange={(e) => setFormData({ ...formData, slug: e.target.value })}
|
||||||
|
className="w-full px-3 py-2 border border-[#e5e7eb] rounded-xl focus:outline-none focus:border-[#f5a623] text-[#00293d] bg-white placeholder:text-[#666666] font-mono text-sm"
|
||||||
|
placeholder="e.g., basic-information"
|
||||||
|
pattern="^[a-z0-9]+(?:-[a-z0-9]+)*$"
|
||||||
|
title="Lowercase letters, digits, and hyphens only (no leading/trailing/consecutive hyphens)"
|
||||||
|
required
|
||||||
|
/>
|
||||||
|
<p className="mt-1 text-xs text-[#666666]">
|
||||||
|
Lowercase letters, digits, and hyphens only. Used in API keys and field references — change with care.
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
<div>
|
<div>
|
||||||
<label className="block text-sm font-medium text-[#00293d] mb-1">
|
<label className="block text-sm font-medium text-[#00293d] mb-1">
|
||||||
Description
|
Description
|
||||||
|
|||||||
@@ -50,6 +50,7 @@ export interface CreateSectionDto {
|
|||||||
|
|
||||||
export interface UpdateSectionDto {
|
export interface UpdateSectionDto {
|
||||||
name?: string;
|
name?: string;
|
||||||
|
slug?: string;
|
||||||
description?: string;
|
description?: string;
|
||||||
icon?: string;
|
icon?: string;
|
||||||
sortOrder?: number;
|
sortOrder?: number;
|
||||||
|
|||||||
Reference in New Issue
Block a user