After improving the faq fonctionality management in adding the pdf upload1
This commit is contained in:
parent
d272c49f46
commit
1ef445f3ee
@ -286,10 +286,20 @@ export const supportConversationUpdateBodySchema = atLeastOneField(
|
|||||||
|
|
||||||
// —— FAQ ——
|
// —— FAQ ——
|
||||||
|
|
||||||
|
const faqCategoryDescriptionSchema = z
|
||||||
|
.union([z.string().max(4000), z.null()])
|
||||||
|
.optional()
|
||||||
|
.transform((v) => {
|
||||||
|
if (v === undefined) return undefined;
|
||||||
|
if (v === null) return null;
|
||||||
|
const trimmed = v.trim();
|
||||||
|
return trimmed.length ? trimmed : null;
|
||||||
|
});
|
||||||
|
|
||||||
export const faqCategoryCreateBodySchema = z.object({
|
export const faqCategoryCreateBodySchema = z.object({
|
||||||
name: z.string().trim().min(1).max(200),
|
name: z.string().trim().min(1).max(200),
|
||||||
slug: z.string().trim().max(200).optional(),
|
slug: z.string().trim().max(200).optional(),
|
||||||
description: z.string().trim().max(4000).nullable().optional(),
|
description: faqCategoryDescriptionSchema,
|
||||||
sortOrder: z.number().int().optional(),
|
sortOrder: z.number().int().optional(),
|
||||||
isActive: z.boolean().optional(),
|
isActive: z.boolean().optional(),
|
||||||
});
|
});
|
||||||
@ -298,7 +308,7 @@ export const faqCategoryUpdateBodySchema = atLeastOneField(
|
|||||||
z.object({
|
z.object({
|
||||||
name: z.string().trim().min(1).max(200).optional(),
|
name: z.string().trim().min(1).max(200).optional(),
|
||||||
slug: z.string().trim().max(200).optional(),
|
slug: z.string().trim().max(200).optional(),
|
||||||
description: z.string().trim().max(4000).nullable().optional(),
|
description: faqCategoryDescriptionSchema,
|
||||||
sortOrder: z.number().int().optional(),
|
sortOrder: z.number().int().optional(),
|
||||||
isActive: z.boolean().optional(),
|
isActive: z.boolean().optional(),
|
||||||
})
|
})
|
||||||
|
|||||||
@ -14,6 +14,7 @@ import {
|
|||||||
MenuItem,
|
MenuItem,
|
||||||
Paper,
|
Paper,
|
||||||
Select,
|
Select,
|
||||||
|
Snackbar,
|
||||||
Stack,
|
Stack,
|
||||||
Switch,
|
Switch,
|
||||||
Tab,
|
Tab,
|
||||||
@ -159,6 +160,9 @@ export function FaqAdminPage() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
const [docBusy, setDocBusy] = useState<'fr' | 'en' | null>(null);
|
const [docBusy, setDocBusy] = useState<'fr' | 'en' | null>(null);
|
||||||
|
const [catToast, setCatToast] = useState<string | null>(null);
|
||||||
|
/** After first save of a brand-new category, keep dialog open so PDFs can be attached. */
|
||||||
|
const [catJustCreated, setCatJustCreated] = useState(false);
|
||||||
|
|
||||||
const saveCatM = useMutation({
|
const saveCatM = useMutation({
|
||||||
mutationFn: async () => {
|
mutationFn: async () => {
|
||||||
@ -166,24 +170,40 @@ export function FaqAdminPage() {
|
|||||||
const body = {
|
const body = {
|
||||||
name: catForm.name.trim(),
|
name: catForm.name.trim(),
|
||||||
slug: catForm.slug.trim() || undefined,
|
slug: catForm.slug.trim() || undefined,
|
||||||
description: catForm.description.trim() || null,
|
description: catForm.description.trim() ? catForm.description.trim() : null,
|
||||||
sortOrder: catForm.sortOrder,
|
sortOrder: Number(catForm.sortOrder) || 0,
|
||||||
isActive: catForm.isActive,
|
isActive: catForm.isActive,
|
||||||
};
|
};
|
||||||
if (editingCat) return adminUpdateFaqCategory(editingCat.id, body);
|
// Capture create-vs-edit before the request; editingCat may flip after create.
|
||||||
return adminCreateFaqCategory(body);
|
const creating = !editingCat;
|
||||||
|
if (editingCat) {
|
||||||
|
const updated = await adminUpdateFaqCategory(editingCat.id, body);
|
||||||
|
return { saved: updated, creating };
|
||||||
|
}
|
||||||
|
const created = await adminCreateFaqCategory(body);
|
||||||
|
return { saved: created, creating };
|
||||||
},
|
},
|
||||||
onSuccess: (saved) => {
|
onSuccess: ({ saved, creating }) => {
|
||||||
setEditingCat(saved);
|
|
||||||
setCatForm({
|
|
||||||
name: saved.name,
|
|
||||||
slug: saved.slug,
|
|
||||||
description: saved.description ?? '',
|
|
||||||
sortOrder: saved.sortOrder,
|
|
||||||
isActive: saved.isActive !== false,
|
|
||||||
});
|
|
||||||
invalidate();
|
invalidate();
|
||||||
// Keep dialog open after create/save so PDFs can be managed immediately.
|
setCatToast(t('admin.faqAdmin.categorySaved'));
|
||||||
|
if (creating) {
|
||||||
|
// Stay open once so the admin can attach optional PDFs.
|
||||||
|
setEditingCat(saved);
|
||||||
|
setCatForm({
|
||||||
|
name: saved.name,
|
||||||
|
slug: saved.slug,
|
||||||
|
description: saved.description ?? '',
|
||||||
|
sortOrder: saved.sortOrder,
|
||||||
|
isActive: saved.isActive !== false,
|
||||||
|
});
|
||||||
|
setCatJustCreated(true);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
setCatDialogOpen(false);
|
||||||
|
setEditingCat(null);
|
||||||
|
setCatForm(emptyCategory());
|
||||||
|
setDocBusy(null);
|
||||||
|
setCatJustCreated(false);
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -192,6 +212,8 @@ export function FaqAdminPage() {
|
|||||||
setEditingCat(null);
|
setEditingCat(null);
|
||||||
setCatForm(emptyCategory());
|
setCatForm(emptyCategory());
|
||||||
setDocBusy(null);
|
setDocBusy(null);
|
||||||
|
setCatJustCreated(false);
|
||||||
|
saveCatM.reset();
|
||||||
};
|
};
|
||||||
|
|
||||||
const deleteCatM = useMutation({
|
const deleteCatM = useMutation({
|
||||||
@ -251,6 +273,8 @@ export function FaqAdminPage() {
|
|||||||
const openCreateCat = () => {
|
const openCreateCat = () => {
|
||||||
setEditingCat(null);
|
setEditingCat(null);
|
||||||
setCatForm(emptyCategory());
|
setCatForm(emptyCategory());
|
||||||
|
setCatJustCreated(false);
|
||||||
|
saveCatM.reset();
|
||||||
setCatDialogOpen(true);
|
setCatDialogOpen(true);
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -263,6 +287,8 @@ export function FaqAdminPage() {
|
|||||||
sortOrder: cat.sortOrder,
|
sortOrder: cat.sortOrder,
|
||||||
isActive: cat.isActive !== false,
|
isActive: cat.isActive !== false,
|
||||||
});
|
});
|
||||||
|
setCatJustCreated(false);
|
||||||
|
saveCatM.reset();
|
||||||
setCatDialogOpen(true);
|
setCatDialogOpen(true);
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -578,20 +604,36 @@ export function FaqAdminPage() {
|
|||||||
</Stack>
|
</Stack>
|
||||||
</Box>
|
</Box>
|
||||||
|
|
||||||
|
{catJustCreated && (
|
||||||
|
<Alert severity="success">{t('admin.faqAdmin.categorySavedAttachPdfs')}</Alert>
|
||||||
|
)}
|
||||||
{saveCatM.error && <Alert severity="error">{(apiErrorMessage(saveCatM.error))}</Alert>}
|
{saveCatM.error && <Alert severity="error">{(apiErrorMessage(saveCatM.error))}</Alert>}
|
||||||
</Stack>
|
</Stack>
|
||||||
</DialogContent>
|
</DialogContent>
|
||||||
<DialogActions>
|
<DialogActions sx={{ px: 3, pb: 2, gap: 1, flexWrap: 'wrap' }}>
|
||||||
<Button onClick={closeCatDialog}>{t('common.cancel')}</Button>
|
{saveCatM.error && (
|
||||||
|
<Typography variant="caption" color="error" sx={{ flex: '1 1 100%', mr: 'auto' }}>
|
||||||
|
{apiErrorMessage(saveCatM.error)}
|
||||||
|
</Typography>
|
||||||
|
)}
|
||||||
|
<Button onClick={closeCatDialog}>{catJustCreated ? t('common.close') : t('common.cancel')}</Button>
|
||||||
<Button
|
<Button
|
||||||
variant="contained"
|
variant="contained"
|
||||||
onClick={() => saveCatM.mutate()}
|
onClick={() => saveCatM.mutate()}
|
||||||
disabled={saveCatM.isPending || docBusy !== null}
|
disabled={saveCatM.isPending || docBusy !== null}
|
||||||
>
|
>
|
||||||
{t('common.save')}
|
{saveCatM.isPending ? t('common.saving') : t('common.save')}
|
||||||
</Button>
|
</Button>
|
||||||
</DialogActions>
|
</DialogActions>
|
||||||
</Dialog>
|
</Dialog>
|
||||||
|
|
||||||
|
<Snackbar
|
||||||
|
open={Boolean(catToast)}
|
||||||
|
autoHideDuration={3500}
|
||||||
|
onClose={() => setCatToast(null)}
|
||||||
|
message={catToast}
|
||||||
|
anchorOrigin={{ vertical: 'bottom', horizontal: 'center' }}
|
||||||
|
/>
|
||||||
</Box>
|
</Box>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2793,6 +2793,8 @@ export const en = {
|
|||||||
orderField: 'Order',
|
orderField: 'Order',
|
||||||
categoryRequired: 'Category and question are required',
|
categoryRequired: 'Category and question are required',
|
||||||
nameRequired: 'Name is required',
|
nameRequired: 'Name is required',
|
||||||
|
categorySaved: 'Category saved',
|
||||||
|
categorySavedAttachPdfs: 'Category saved. You can attach PDF guides below, then close.',
|
||||||
documentsTitle: 'Documents to download',
|
documentsTitle: 'Documents to download',
|
||||||
documentsHint: 'Optional. Attach a French and/or English PDF guide for this category.',
|
documentsHint: 'Optional. Attach a French and/or English PDF guide for this category.',
|
||||||
pdfFrLabel: 'French PDF (FR)',
|
pdfFrLabel: 'French PDF (FR)',
|
||||||
|
|||||||
@ -2817,6 +2817,8 @@ export const fr = {
|
|||||||
orderField: 'Ordre',
|
orderField: 'Ordre',
|
||||||
categoryRequired: 'Catégorie et question requises',
|
categoryRequired: 'Catégorie et question requises',
|
||||||
nameRequired: 'Nom requis',
|
nameRequired: 'Nom requis',
|
||||||
|
categorySaved: 'Catégorie enregistrée',
|
||||||
|
categorySavedAttachPdfs: 'Catégorie enregistrée. Vous pouvez joindre les PDF ci-dessous, puis fermer.',
|
||||||
documentsTitle: 'Documents à télécharger',
|
documentsTitle: 'Documents à télécharger',
|
||||||
documentsHint: 'Optionnel. Joignez un guide PDF en français et/ou en anglais pour cette catégorie.',
|
documentsHint: 'Optionnel. Joignez un guide PDF en français et/ou en anglais pour cette catégorie.',
|
||||||
pdfFrLabel: 'PDF français (FR)',
|
pdfFrLabel: 'PDF français (FR)',
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user