From 860382fc444cedb11a970900d706ab5c6942fbae Mon Sep 17 00:00:00 2001 From: Simon G <17337190+SimonGodefroid@users.noreply.github.com> Date: Thu, 11 Sep 2025 20:41:27 +0400 Subject: [PATCH 1/2] SAVEPOINT --- prisma/schema.prisma | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/prisma/schema.prisma b/prisma/schema.prisma index fdeaac8..e887f25 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -178,6 +178,7 @@ model Report { campaignId String? // Foreign key to link to a campaign campaign Campaign? @relation(fields: [campaignId], references: [id], onDelete: SetNull) notifiedAt DateTime? // this made a mess + type ReportType @default(Bug) } model Comment { @@ -276,3 +277,11 @@ model Invitation { // FIXME: let's think this through // @@unique([campaignId, inviteeId]) // Added unique constraint } + +enum ReportType { + Bug + Feature + Discussion + Announcement + Question +} From 70d081536af0fa896a00c855dcb352a2eb11553c Mon Sep 17 00:00:00 2001 From: Simon G <17337190+SimonGodefroid@users.noreply.github.com> Date: Thu, 11 Sep 2025 20:50:03 +0400 Subject: [PATCH 2/2] SAVEPOINT --- .../reports/forms/create-report-form.tsx | 124 +++++++++++------- 1 file changed, 80 insertions(+), 44 deletions(-) diff --git a/src/components/reports/forms/create-report-form.tsx b/src/components/reports/forms/create-report-form.tsx index b415b7c..294f79a 100644 --- a/src/components/reports/forms/create-report-form.tsx +++ b/src/components/reports/forms/create-report-form.tsx @@ -6,7 +6,16 @@ import { redirect, useRouter } from 'next/navigation'; import { createReport } from '@/actions/reports/create'; import { ReportWithTags, UserWithCompanies } from '@/types'; -import { Button, Input, Selection, Textarea, Tooltip, Spinner } from '@nextui-org/react'; +import { + Button, + Input, + Select, + Selection, + SelectItem, + Spinner, + Textarea, + Tooltip, +} from '@nextui-org/react'; import { Tag } from '@prisma/client'; import { useFormState } from 'react-dom'; // import { useFormState } from 'react-dom'; @@ -16,12 +25,12 @@ import { toast } from 'react-toastify'; import { DragNDropFileUpload } from '@/components/common/drag-n-drop-file-upload'; import { EditorClient } from '@/components/common/editor'; import ImageTooltip from '@/components/common/image-tooltip'; +import SystemInfoBox from '@/components/common/system-info-box'; // import CompanySelector from '../../companies/company-selector'; import ImpactSelector from './impact-selector'; import SeveritySelector from './severity-selector'; import TagsSelector from './tags-selector'; -import SystemInfoBox from '@/components/common/system-info-box'; export const CreateReportForm = ({ user, @@ -46,31 +55,30 @@ export const CreateReportForm = ({ const [images, setImages] = React.useState< { url: string; filename: string }[] >([]); - + const [isSubmitting, setIsSubmitting] = useState(false); const [isRedirecting, setIsRedirecting] = useState(false); - + useEffect(() => { - if (formState?.success) { - (async()=>{ - setIsRedirecting(true); - await toast.success( - `The report has been created it will be reviewed by an admin before publication !`, - ); - router.push(`/reports`); // Use router.push instead of redirect - })() - } - const hasFieldErrors = - Object.keys(formState?.errors || {}).length > 0; + if (formState?.success) { + (async () => { + setIsRedirecting(true); + await toast.success( + `The report has been created it will be reviewed by an admin before publication !`, + ); + router.push(`/reports`); // Use router.push instead of redirect + })(); + } + const hasFieldErrors = Object.keys(formState?.errors || {}).length > 0; - if (formState?.errors._form?.length || hasFieldErrors) { - toast.error( - formState.errors._form?.join(', ') || - 'Please fix the highlighted errors.', - ); - setIsSubmitting(false); - } -}, [formState, router]); // Add router to dependencies + if (formState?.errors._form?.length || hasFieldErrors) { + toast.error( + formState.errors._form?.join(', ') || + 'Please fix the highlighted errors.', + ); + setIsSubmitting(false); + } + }, [formState, router]); // Add router to dependencies const [url, setUrl] = useState(''); // const [selectedCampaign, setSelectedCampaign] = useState(null); @@ -86,8 +94,8 @@ export const CreateReportForm = ({ // }; const handleSubmit = (formData: FormData) => { - setIsSubmitting(true); - action(formData); + setIsSubmitting(true); + action(formData); }; const handleCancel = () => { @@ -131,17 +139,42 @@ export const CreateReportForm = ({
- + label="Report type" + placeholder="Select the type of report you want to create" + // isDisabled={isSubmitting} + items={[{ label: 'a', value: 'a' }]} + > + {Object.values([ + { label: 'Bug', value: 'Bug' }, + { label: 'Feature', value: 'Feature' }, + { label: 'Discussion', value: 'Discussion' }, + { label: 'Question', value: 'Question' }, + { label: 'Announcement', value: 'Announcement' }, + ]).map((type) => ( + + {type.label} + + ))} +
+ {/*
- - + +
@@ -270,7 +307,6 @@ export const CreateReportForm = ({ {/* Right */}
- {/* {!user && (
- ) : ( -
); -}; \ No newline at end of file +};