-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial merge of messaging & tickets. Will have a additional merge in the future, this is to introduce groundwork and schema changes. * Add socketii, pusher, and trpc * remove realtime package * Migrations * Fix trpc, add db relations * Temp hide tickets * Format + fix lockfile
- Loading branch information
1 parent
431030c
commit 8361616
Showing
23 changed files
with
2,870 additions
and
47 deletions.
There are no files selected for viewing
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,34 @@ | ||
import { fetchRequestHandler } from "@trpc/server/adapters/fetch"; | ||
import { type NextRequest } from "next/server"; | ||
|
||
import { env } from "@/env"; | ||
import { appRouter } from "@/server/api/root"; | ||
import { createTRPCContext } from "@/server/api/trpc"; | ||
|
||
/** | ||
* This wraps the `createTRPCContext` helper and provides the required context for the tRPC API when | ||
* handling a HTTP request (e.g. when you make requests from Client Components). | ||
*/ | ||
const createContext = async (req: NextRequest) => { | ||
return createTRPCContext({ | ||
headers: req.headers, | ||
}); | ||
}; | ||
|
||
const handler = (req: NextRequest) => | ||
fetchRequestHandler({ | ||
endpoint: "/api/trpc", | ||
req, | ||
router: appRouter, | ||
createContext: () => createContext(req), | ||
onError: | ||
env.NODE_ENV === "development" | ||
? ({ path, error }) => { | ||
console.error( | ||
`❌ tRPC failed on ${path ?? "<no-path>"}: ${error.message}`, | ||
); | ||
} | ||
: undefined, | ||
}); | ||
|
||
export { handler as GET, handler as POST }; |
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,14 @@ | ||
import TicketList from "@/components/dash/tickets/TicketList"; | ||
|
||
export default function TicketsLayout({ | ||
children, | ||
}: { | ||
children: React.ReactNode; | ||
}) { | ||
return ( | ||
<div className="mx-auto grid h-[calc(100vh-7rem)] w-screen grid-cols-5 gap-x-3"> | ||
<TicketList /> | ||
<div className="col-span-4 h-full">{children}</div> | ||
</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,60 @@ | ||
"use client"; | ||
import { useState } from "react"; | ||
import { Input } from "@/components/shadcn/ui/input"; | ||
import { Label } from "@/components/shadcn/ui/label"; | ||
import { Textarea } from "@/components/shadcn/ui/textarea"; | ||
import { Button } from "@/components/shadcn/ui/button"; | ||
import { api } from "@/trpc/react"; | ||
import { toast } from "sonner"; | ||
|
||
export default function Page() { | ||
const [title, setTitle] = useState(""); | ||
const [description, setDescription] = useState(""); | ||
|
||
const createTicket = api.tickets.create.useMutation(); | ||
|
||
async function runCreateTicket() { | ||
if (title.length > 3 && description.length > 10) { | ||
const result = await createTicket.mutateAsync({ | ||
title, | ||
description, | ||
}); | ||
if (result.success) { | ||
toast.success("Ticket created successfully!"); | ||
console.log( | ||
"created ticket with ID " + | ||
result.ticketID + | ||
" and chat with ID " + | ||
result.chatID, | ||
); | ||
} | ||
} else { | ||
toast.error( | ||
"Your title or description is too short! Please try again.", | ||
); | ||
} | ||
} | ||
|
||
return ( | ||
<div className="h-full pt-20"> | ||
<div className="mx-auto max-w-3xl"> | ||
<h1 className="text-3xl font-black">New Ticket</h1> | ||
<div className="flex flex-col items-start gap-y-5 pt-10"> | ||
<div className="w-full"> | ||
<Label className="pb-2">Title</Label> | ||
<Input onChange={(e) => setTitle(e.target.value)} /> | ||
</div> | ||
<div className="w-full"> | ||
<Label className="mb-1">Description</Label> | ||
<Textarea | ||
onChange={(e) => setDescription(e.target.value)} | ||
/> | ||
</div> | ||
<Button onClick={() => runCreateTicket()}> | ||
Create Ticket | ||
</Button> | ||
</div> | ||
</div> | ||
</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,7 @@ | ||
export default function Page() { | ||
return ( | ||
<main className="flex h-full items-center justify-center"> | ||
No Ticket Selected | ||
</main> | ||
); | ||
} |
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,43 @@ | ||
"use client"; | ||
|
||
import { title } from "process"; | ||
|
||
const dummyTickets = [ | ||
{ | ||
title: "Ticket 1", | ||
lastMessage: "howdy this is a message", | ||
lastMessageDate: "2023-05-01", | ||
lastMessageAuthor: "@user", | ||
}, | ||
{ | ||
title: "Ticket 2", | ||
lastMessage: "howdy this is a message 2", | ||
lastMessageDate: "2023-05-01", | ||
lastMessageAuthor: "@user", | ||
}, | ||
{ | ||
title: "Ticket 3", | ||
lastMessage: "howdy this is a message 3", | ||
lastMessageDate: "2023-05-01", | ||
lastMessageAuthor: "@user", | ||
}, | ||
]; | ||
|
||
export default function TicketList() { | ||
return ( | ||
<div className="border-r border-r-muted"> | ||
{dummyTickets.map((ticket) => ( | ||
<TicketItem key={ticket.title} /> | ||
))} | ||
</div> | ||
); | ||
} | ||
|
||
function TicketItem() { | ||
return ( | ||
<div className="flex h-16 flex-col justify-center border-b border-b-muted px-5 py-4"> | ||
<h3 className="text-sm font-bold">Ticket Name</h3> | ||
<p className="text-xs text-muted-foreground">Last Message</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
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,23 @@ | ||
import { ticketsRouter } from "@/server/api/routers/tickets"; | ||
import { createCallerFactory, createTRPCRouter } from "@/server/api/trpc"; | ||
|
||
/** | ||
* This is the primary router for your server. | ||
* | ||
* All routers added in /api/routers should be manually added here. | ||
*/ | ||
export const appRouter = createTRPCRouter({ | ||
tickets: ticketsRouter, | ||
}); | ||
|
||
// export type definition of API | ||
export type AppRouter = typeof appRouter; | ||
|
||
/** | ||
* Create a server-side caller for the tRPC API. | ||
* @example | ||
* const trpc = createCaller(createContext); | ||
* const res = await trpc.post.all(); | ||
* ^? Post[] | ||
*/ | ||
export const createCaller = createCallerFactory(appRouter); |
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,31 @@ | ||
import { z } from "zod"; | ||
|
||
import { createTRPCRouter, publicProcedure } from "@/server/api/trpc"; | ||
|
||
export const postRouter = createTRPCRouter({ | ||
hello: publicProcedure | ||
.input(z.object({ text: z.string() })) | ||
.query(({ input }) => { | ||
return { | ||
greeting: `Hello ${input.text}`, | ||
}; | ||
}), | ||
|
||
create: publicProcedure | ||
.input(z.object({ name: z.string().min(1) })) | ||
.mutation(async ({ ctx, input }) => { | ||
// simulate a slow db call | ||
await new Promise((resolve) => setTimeout(resolve, 1000)); | ||
|
||
// await ctx.db.insert(posts).values({ | ||
// name: input.name, | ||
// }); | ||
}), | ||
|
||
getLatest: publicProcedure.query(({ ctx }) => { | ||
// return ctx.db.query.posts.findFirst({ | ||
// orderBy: (posts, { desc }) => [desc(posts.createdAt)], | ||
// }); | ||
return null; | ||
}), | ||
}); |
Oops, something went wrong.