-
Notifications
You must be signed in to change notification settings - Fork 2
Create error report #381
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Castro19
wants to merge
11
commits into
main
Choose a base branch
from
create-error-report
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Create error report #381
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
8f3764e
create shared type for ErrorDocument
Castro19 2e08e0e
Create ErrorFormComponent
Castro19 9431170
creating the api endpoint
Castro19 c2efa07
creating the service and collection functions
Castro19 af59af3
linking to express router
Castro19 337e877
linking to shared export
Castro19 0cca82b
crud function
Castro19 8681a15
adding redux slice
Castro19 9fd7059
Dispatching the action
Castro19 dc2f54b
Update test-utils.tsx
Castro19 df089a0
Update ReportError.tsx
Castro19 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,256 @@ | ||
| import { useForm } from "react-hook-form"; | ||
| import { zodResolver } from "@hookform/resolvers/zod"; | ||
| import { z } from "zod"; | ||
| import { useAppDispatch, errorActions } from "@/redux"; | ||
| import { Button } from "@/components/ui/button"; | ||
| import { Form } from "@/components/ui/form"; | ||
| import { Input } from "@/components/ui/input"; | ||
| import { Textarea } from "@/components/ui/textarea"; | ||
| import { | ||
| Select, | ||
| SelectContent, | ||
| SelectItem, | ||
| SelectTrigger, | ||
| SelectValue, | ||
| } from "@/components/ui/select"; | ||
| import { | ||
| Card, | ||
| CardContent, | ||
| CardDescription, | ||
| CardHeader, | ||
| CardTitle, | ||
| } from "@/components/ui/card"; | ||
| import { toast } from "@/components/ui/use-toast"; | ||
| import { ErrorDocument } from "@polylink/shared/types"; | ||
| import { CreateErrorReportData } from "@/redux/error/errorSlice"; | ||
|
|
||
| // Define the Zod schema for error reporting | ||
| const errorReportSchema = z.object({ | ||
| title: z.string().min(1, "Title is required"), | ||
| description: z.string().min(1, "Description is required"), | ||
| type: z.enum(["bug", "feature-request", "improvement", "other"]), | ||
| severity: z.enum(["low", "medium", "high", "critical"]), | ||
| stepsToReproduce: z.string().optional(), | ||
| expectedBehavior: z.string().optional(), | ||
| actualBehavior: z.string().optional(), | ||
| environment: z | ||
| .object({ | ||
| browser: z.string().optional(), | ||
| operatingSystem: z.string().optional(), | ||
| device: z.string().optional(), | ||
| }) | ||
| .optional(), | ||
| }); | ||
|
|
||
| type ErrorReportForm = Omit< | ||
| ErrorDocument, | ||
| "_id" | "createdAt" | "updatedAt" | "status" | "userId" | ||
| >; | ||
|
|
||
| export function ReportError() { | ||
| const dispatch = useAppDispatch(); | ||
|
|
||
| const form = useForm<ErrorReportForm>({ | ||
| resolver: zodResolver(errorReportSchema), | ||
| defaultValues: { | ||
| title: "", | ||
| description: "", | ||
| type: "bug", | ||
| severity: "medium", | ||
| stepsToReproduce: "", | ||
| expectedBehavior: "", | ||
| actualBehavior: "", | ||
| environment: { | ||
| browser: "", | ||
| operatingSystem: "", | ||
| device: "", | ||
| }, | ||
| }, | ||
| }); | ||
|
|
||
| const onSubmit = async (data: ErrorReportForm) => { | ||
| try { | ||
| await dispatch( | ||
| errorActions.submitErrorReport(data as CreateErrorReportData) | ||
| ).unwrap(); | ||
| toast({ | ||
| title: "Success", | ||
| description: "Error report submitted successfully", | ||
| }); | ||
| form.reset(); | ||
| } catch (error) { | ||
| toast({ | ||
| title: "Error", | ||
| description: "Failed to submit error report. Please try again.", | ||
| variant: "destructive", | ||
| }); | ||
| } | ||
| }; | ||
|
|
||
| return ( | ||
| <div className="mx-auto"> | ||
| <Card className="shadow-lg"> | ||
| <CardHeader> | ||
| <CardTitle>Report an Issue</CardTitle> | ||
| <CardDescription> | ||
| Help us improve by reporting any issues you encounter | ||
| </CardDescription> | ||
| </CardHeader> | ||
| <CardContent> | ||
| <Form {...form}> | ||
| <form onSubmit={form.handleSubmit(onSubmit)} className="space-y-5"> | ||
| <div> | ||
| <label className="block text-sm font-medium mb-1">Title</label> | ||
| <Input {...form.register("title")} placeholder="Issue title" /> | ||
| {form.formState.errors.title && ( | ||
| <p className="mt-1 text-xs text-red-500"> | ||
| {form.formState.errors.title.message} | ||
| </p> | ||
| )} | ||
| </div> | ||
|
|
||
| <div> | ||
| <label className="block text-sm font-medium mb-1"> | ||
| Description | ||
| </label> | ||
| <Textarea | ||
| {...form.register("description")} | ||
| placeholder="Describe the issue in detail" | ||
| rows={4} | ||
| /> | ||
| {form.formState.errors.description && ( | ||
| <p className="mt-1 text-xs text-red-500"> | ||
| {form.formState.errors.description.message} | ||
| </p> | ||
| )} | ||
| </div> | ||
|
|
||
| <div className="grid grid-cols-1 sm:grid-cols-2 gap-4"> | ||
| <div> | ||
| <label className="block text-sm font-medium mb-1">Type</label> | ||
| <Select | ||
| onValueChange={(v: string) => | ||
| form.setValue( | ||
| "type", | ||
| v as "bug" | "feature-request" | "improvement" | "other" | ||
| ) | ||
| } | ||
| defaultValue={form.getValues("type")} | ||
| > | ||
| <SelectTrigger className="w-full bg-white dark:bg-gray-800 border-2 border-slate-200 dark:border-slate-600"> | ||
| <SelectValue placeholder="Select type" /> | ||
| </SelectTrigger> | ||
| <SelectContent> | ||
| <SelectItem value="bug">Bug</SelectItem> | ||
| <SelectItem value="feature-request">Feature</SelectItem> | ||
| <SelectItem value="improvement">Improvement</SelectItem> | ||
| <SelectItem value="other">Other</SelectItem> | ||
| </SelectContent> | ||
| </Select> | ||
| </div> | ||
|
|
||
| <div> | ||
| <label className="block text-sm font-medium mb-1"> | ||
| Severity | ||
| </label> | ||
| <Select | ||
| onValueChange={(v: string) => | ||
| form.setValue( | ||
| "severity", | ||
| v as "low" | "medium" | "high" | "critical" | ||
| ) | ||
| } | ||
| defaultValue={form.getValues("severity")} | ||
| > | ||
| <SelectTrigger className="w-full bg-white dark:bg-gray-800 border-2 border-slate-200 dark:border-slate-600"> | ||
| <SelectValue placeholder="Select severity" /> | ||
| </SelectTrigger> | ||
| <SelectContent> | ||
| <SelectItem value="low">Low</SelectItem> | ||
| <SelectItem value="medium">Medium</SelectItem> | ||
| <SelectItem value="high">High</SelectItem> | ||
| <SelectItem value="critical">Critical</SelectItem> | ||
| </SelectContent> | ||
| </Select> | ||
| </div> | ||
| </div> | ||
|
|
||
| <div> | ||
| <label className="block text-sm font-medium mb-1"> | ||
| Steps to Reproduce | ||
| </label> | ||
| <Textarea | ||
| {...form.register("stepsToReproduce")} | ||
| placeholder="Optional" | ||
| rows={3} | ||
| /> | ||
| </div> | ||
|
|
||
| <div className="grid grid-cols-1 sm:grid-cols-2 gap-4"> | ||
| <div> | ||
| <label className="block text-sm font-medium mb-1"> | ||
| Expected Behavior | ||
| </label> | ||
| <Textarea | ||
| {...form.register("expectedBehavior")} | ||
| placeholder="Optional" | ||
| rows={2} | ||
| /> | ||
| </div> | ||
| <div> | ||
| <label className="block text-sm font-medium mb-1"> | ||
| Actual Behavior | ||
| </label> | ||
| <Textarea | ||
| {...form.register("actualBehavior")} | ||
| placeholder="Optional" | ||
| rows={2} | ||
| /> | ||
| </div> | ||
| </div> | ||
|
|
||
| <div> | ||
| <h3 className="text-sm font-medium mb-2"> | ||
| Environment Details (Optional) | ||
| </h3> | ||
| <div className="grid grid-cols-1 sm:grid-cols-3 gap-4"> | ||
| <div> | ||
| <label className="block text-sm mb-1">Browser</label> | ||
| <Input | ||
| {...form.register("environment.browser")} | ||
| placeholder="e.g. Chrome 90" | ||
| /> | ||
| </div> | ||
| <div> | ||
| <label className="block text-sm mb-1"> | ||
| Operating System | ||
| </label> | ||
| <Input | ||
| {...form.register("environment.operatingSystem")} | ||
| placeholder="e.g. Windows 10" | ||
| /> | ||
| </div> | ||
| <div> | ||
| <label className="block text-sm mb-1">Device</label> | ||
| <Input | ||
| {...form.register("environment.device")} | ||
| placeholder="e.g. Desktop" | ||
| /> | ||
| </div> | ||
| </div> | ||
| </div> | ||
|
|
||
| <div className="text-right"> | ||
| <Button type="submit" variant="default" className="py-2 px-6"> | ||
| Submit | ||
| </Button> | ||
| </div> | ||
| </form> | ||
| </Form> | ||
| </CardContent> | ||
| </Card> | ||
| </div> | ||
| ); | ||
| } | ||
|
|
||
| export default ReportError; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| import { ErrorDocument } from "@polylink/shared/types"; | ||
| import { environment, serverUrl } from "@/helpers/getEnvironmentVars"; | ||
|
|
||
| type CreateErrorReportData = Omit< | ||
| ErrorDocument, | ||
| "_id" | "createdAt" | "updatedAt" | "status" | ||
| >; | ||
|
|
||
| export async function createErrorReport( | ||
| errorData: CreateErrorReportData | ||
| ): Promise<{ message: string; errorId: string }> { | ||
| try { | ||
| const response = await fetch(`${serverUrl}/errors`, { | ||
| method: "POST", | ||
| credentials: "include", | ||
| headers: { "Content-Type": "application/json" }, | ||
| body: JSON.stringify(errorData), | ||
| }); | ||
|
|
||
| if (!response.ok) { | ||
| throw new Error(`Error: ${response.status}`); | ||
| } | ||
|
|
||
| const data = await response.json(); | ||
| return data as { message: string; errorId: string }; | ||
| } catch (error) { | ||
| if (environment === "dev") { | ||
| console.error("Failed to create error report: ", error); | ||
| } | ||
| throw error; | ||
| } | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] The
CreateErrorReportDatatype is duplicated betweencrudError.tsand the Redux slice. Consider centralizing this type in the shared types to prevent drift and ensure consistency.