-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add navbar, ticket explore page and ticket view page. Improve login s…
…ystem.
- Loading branch information
ar00n
committed
Sep 19, 2023
1 parent
8df2dc7
commit f49adb0
Showing
19 changed files
with
2,123 additions
and
132 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains 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 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 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 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,28 @@ | ||
import { getTicket } from "@/lib/tickets" | ||
const dayjs = require('dayjs') | ||
var localizedFormat = require('dayjs/plugin/localizedFormat') | ||
dayjs.extend(localizedFormat) | ||
|
||
export default async function TicketView ({ params }) { | ||
if(isNaN(Number(params.id))) { | ||
return <a>Invalid ticket ID.</a> | ||
} | ||
|
||
const data = await getTicket(params.id) | ||
|
||
if (!data.success) { | ||
return <a>{data.message}</a> | ||
} | ||
|
||
return ( | ||
<div> | ||
<h1 className="text-2xl">{data.ticket.title}</h1> | ||
<h3 className="text-xs">{dayjs(data.ticket.created_at).format('L LT')}</h3> | ||
<p className="pt-2">{data.ticket.message}</p> | ||
|
||
<p>Severity: {data.ticket.severity}</p> | ||
<p>Requester: {data.ticket.requester}</p> | ||
<p>Assignee: {data.ticket .assignee ? data.assignee : 'N/A'}</p> | ||
</div> | ||
) | ||
} |
This file contains 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,119 @@ | ||
"use client" | ||
|
||
import React, { useEffect, useState } from 'react' | ||
|
||
import { useRouter } from 'next/navigation' | ||
|
||
import { useForm } from "react-hook-form" | ||
import * as z from "zod" | ||
|
||
import { zodResolver } from "@hookform/resolvers/zod" | ||
import { Form, FormControl, FormDescription, FormField, FormItem, FormLabel, FormMessage } from "@/components/ui/form" | ||
import { Button } from "@/components/ui/button" | ||
import { Input } from '@/components/ui/input' | ||
import { Alert, AlertDescription, AlertTitle } from '@/components/ui/alert' | ||
import { verifySession } from '@/lib/user' | ||
import { Slider } from '@/components/ui/slider' | ||
import { Textarea } from '@/components/ui/textarea' | ||
import { createTicket } from '@/lib/tickets' | ||
import { AlertCircle, CheckCircle2 } from 'lucide-react' | ||
|
||
const formSchema = z.object({ | ||
title: z.string().min(8).max(32), | ||
severity: z.number().min(1).max(5), | ||
message: z.string().min(8).max(32) | ||
}) | ||
|
||
export default function CreateTicketForm () { | ||
const [result, setResult] = useState({}) | ||
const router = useRouter(); | ||
|
||
useEffect(() => { | ||
verifySession().then(res => { | ||
if (!res.success) { | ||
router.push('/login') | ||
} | ||
}) | ||
}, []) | ||
|
||
const form = useForm({ | ||
resolver: zodResolver(formSchema), | ||
defaultValues: { | ||
title: "", | ||
severity: 5, | ||
message: "", | ||
}, | ||
}) | ||
|
||
async function onSubmit(values) { | ||
const res = await createTicket(values) | ||
setResult(res) | ||
if (res.success) { | ||
setTimeout(() => router.push('/'), 2000) | ||
} | ||
} | ||
|
||
return ( | ||
<Form {...form}> | ||
<form onSubmit={form.handleSubmit(onSubmit)} className="space-y-8"> | ||
<FormField | ||
control={form.control} | ||
name="title" | ||
render={({ field }) => ( | ||
<FormItem> | ||
<FormLabel>Title</FormLabel> | ||
<FormControl> | ||
<Input placeholder="shadcn" {...field} /> | ||
</FormControl> | ||
<FormMessage /> | ||
</FormItem> | ||
)} | ||
/> | ||
<FormField | ||
control={form.control} | ||
name="severity" | ||
render={({ field: { value, onChange } }) => ( | ||
<FormItem> | ||
<FormLabel>Severity: {value}</FormLabel> | ||
<FormControl> | ||
<Slider defaultValue={[5]} max={5} min={1} step={1} inverted={true} x={value} onValueChange={(e) => {onChange(e[0])}} /> | ||
</FormControl> | ||
<FormDescription> | ||
This is your public display name. | ||
</FormDescription> | ||
<FormMessage /> | ||
</FormItem> | ||
)} | ||
/> | ||
<FormField | ||
control={form.control} | ||
name="message" | ||
render={({ field }) => ( | ||
<FormItem> | ||
<FormLabel>Message</FormLabel> | ||
<FormControl> | ||
<Textarea placeholder="shadcn" {...field} /> | ||
</FormControl> | ||
<FormDescription> | ||
This is your public display name. | ||
</FormDescription> | ||
<FormMessage /> | ||
</FormItem> | ||
)} | ||
/> | ||
{ | ||
result.success != null ? | ||
<Alert variant={result.success ? 'success' : 'destructive'}> | ||
{result.success ? <CheckCircle2 className="h-4 w-4" /> : <AlertCircle className="h-4 w-4" />} | ||
<AlertTitle>{result.success ? 'Success' : 'Error'}</AlertTitle> | ||
<AlertDescription> | ||
{result.message} | ||
</AlertDescription> | ||
</Alert> | ||
: '' | ||
} | ||
<Button type="submit">Create</Button> | ||
</form> | ||
</Form> | ||
) | ||
} |
This file contains 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 |
---|---|---|
@@ -1,5 +1,14 @@ | ||
export default function Tickets() { | ||
import TicketTable from "@/components/TicketTable" | ||
import { getTickets } from "@/lib/tickets" | ||
|
||
export default async function Tickets() { | ||
const data = await getTickets(1, 10) | ||
|
||
if (!data.success) { | ||
return <a>Error: {data.message}</a> | ||
} | ||
|
||
return ( | ||
|
||
<TicketTable data={data.tickets} /> | ||
) | ||
} |
Oops, something went wrong.