Skip to content

Commit

Permalink
Update contributing
Browse files Browse the repository at this point in the history
  • Loading branch information
evadecker committed Dec 7, 2024
1 parent 4d3c09d commit 76d663e
Show file tree
Hide file tree
Showing 5 changed files with 142 additions and 140 deletions.
1 change: 1 addition & 0 deletions docs/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ Below are Namesake's core dependencies. The links below each lead to docs.
| ----------------------------------------------------------------------------------- | -------------------------------------------------- |
| [Convex](https://docs.convex.dev/) | Type-safe database, file storage, realtime updates |
| [Convex Auth](https://labs.convex.dev/auth) | User authentication |
| [SurveyJS](https://surveyjs.io/documentation) | Form building, validation, and display |
| [TanStack Router](https://tanstack.com/router/latest/docs/framework/react/overview) | File-based routing |
| [React](https://react.dev/reference/react) | Front-end web framework |
| [React Aria](https://react-spectrum.adobe.com/react-aria) | Accessible components and design system |
Expand Down
36 changes: 18 additions & 18 deletions src/routes/_authenticated/admin/documents.$documentId.tsx
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
import { PageHeader } from '@/components/app'
import { Badge, Link } from '@/components/common'
import { api } from '@convex/_generated/api'
import type { Id } from '@convex/_generated/dataModel'
import { createFileRoute } from '@tanstack/react-router'
import { useQuery } from 'convex/react'
import { PageHeader } from "@/components/app";
import { Badge, Link } from "@/components/common";
import { api } from "@convex/_generated/api";
import type { Id } from "@convex/_generated/dataModel";
import { createFileRoute } from "@tanstack/react-router";
import { useQuery } from "convex/react";

export const Route = createFileRoute(
'/_authenticated/admin/documents/$documentId',
"/_authenticated/admin/documents/$documentId",
)({
component: AdminDocumentDetailRoute,
})
});

function AdminDocumentDetailRoute() {
const { documentId } = Route.useParams()
const { documentId } = Route.useParams();
const document = useQuery(api.documents.getById, {
documentId: documentId as Id<'documents'>,
})
documentId: documentId as Id<"documents">,
});
const fileUrl = useQuery(api.documents.getURL, {
documentId: documentId as Id<'documents'>,
})
documentId: documentId as Id<"documents">,
});

if (document === undefined) return
if (document === null) return 'Document not found'
if (document === undefined) return;
if (document === null) return "Document not found";

return (
<div>
Expand All @@ -36,10 +36,10 @@ function AdminDocumentDetailRoute() {
>
<Link
href={{
to: '/admin/quests/$questId',
to: "/admin/quests/$questId",
params: { questId: document.questId },
}}
button={{ variant: 'secondary' }}
button={{ variant: "secondary" }}
>
Go to quest
</Link>
Expand All @@ -52,5 +52,5 @@ function AdminDocumentDetailRoute() {
/>
)}
</div>
)
);
}
138 changes: 69 additions & 69 deletions src/routes/_authenticated/admin/documents.index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { PageHeader } from '@/components/app'
import { PageHeader } from "@/components/app";
import {
Badge,
Button,
Expand All @@ -21,75 +21,75 @@ import {
TableHeader,
TableRow,
TextField,
} from '@/components/common'
import { api } from '@convex/_generated/api'
import type { DataModel, Id } from '@convex/_generated/dataModel'
import { JURISDICTIONS, type Jurisdiction } from '@convex/constants'
import { createFileRoute } from '@tanstack/react-router'
import { useMutation, useQuery } from 'convex/react'
import { Ellipsis, FileText, Plus } from 'lucide-react'
import { useState } from 'react'
} from "@/components/common";
import { api } from "@convex/_generated/api";
import type { DataModel, Id } from "@convex/_generated/dataModel";
import { JURISDICTIONS, type Jurisdiction } from "@convex/constants";
import { createFileRoute } from "@tanstack/react-router";
import { useMutation, useQuery } from "convex/react";
import { Ellipsis, FileText, Plus } from "lucide-react";
import { useState } from "react";

export const Route = createFileRoute('/_authenticated/admin/documents/')({
export const Route = createFileRoute("/_authenticated/admin/documents/")({
component: DocumentsRoute,
})
});

const NewDocumentModal = ({
isOpen,
onOpenChange,
onSubmit,
}: {
isOpen: boolean
onOpenChange: (isOpen: boolean) => void
onSubmit: () => void
isOpen: boolean;
onOpenChange: (isOpen: boolean) => void;
onSubmit: () => void;
}) => {
const generateUploadUrl = useMutation(api.documents.generateUploadUrl)
const uploadPDF = useMutation(api.documents.upload)
const createDocument = useMutation(api.documents.create)
const quests = useQuery(api.quests.getAllActive)
const [isSubmitting, setIsSubmitting] = useState(false)
const [file, setFile] = useState<File | null>(null)
const [title, setTitle] = useState('')
const [code, setCode] = useState('')
const [jurisdiction, setJurisdiction] = useState<Jurisdiction | null>(null)
const [questId, setQuestId] = useState<Id<'quests'> | null>(null)
const generateUploadUrl = useMutation(api.documents.generateUploadUrl);
const uploadPDF = useMutation(api.documents.upload);
const createDocument = useMutation(api.documents.create);
const quests = useQuery(api.quests.getAllActive);
const [isSubmitting, setIsSubmitting] = useState(false);
const [file, setFile] = useState<File | null>(null);
const [title, setTitle] = useState("");
const [code, setCode] = useState("");
const [jurisdiction, setJurisdiction] = useState<Jurisdiction | null>(null);
const [questId, setQuestId] = useState<Id<"quests"> | null>(null);

const clearForm = () => {
setFile(null)
setTitle('')
setCode('')
setJurisdiction(null)
setQuestId(null)
}
setFile(null);
setTitle("");
setCode("");
setJurisdiction(null);
setQuestId(null);
};

const handleSubmit = async (e: React.FormEvent<HTMLFormElement>) => {
e.preventDefault()
e.preventDefault();

if (jurisdiction === null) throw new Error('Jurisdiction is required')
if (file === null) throw new Error('File is required')
if (questId === null) throw new Error('Quest is required')
if (jurisdiction === null) throw new Error("Jurisdiction is required");
if (file === null) throw new Error("File is required");
if (questId === null) throw new Error("Quest is required");

setIsSubmitting(true)
setIsSubmitting(true);
const documentId = await createDocument({
title,
jurisdiction,
code,
questId,
})
});

const postUrl = await generateUploadUrl()
const postUrl = await generateUploadUrl();
const result = await fetch(postUrl, {
method: 'POST',
headers: { 'Content-Type': file.type },
method: "POST",
headers: { "Content-Type": file.type },
body: file,
})
const { storageId } = await result.json()
});
const { storageId } = await result.json();

await uploadPDF({ documentId, storageId })
await uploadPDF({ documentId, storageId });

clearForm()
onSubmit()
}
clearForm();
onSubmit();
};

return (
<Modal
Expand Down Expand Up @@ -124,33 +124,33 @@ const NewDocumentModal = ({
<ComboBox
label="Quest"
selectedKey={questId}
onSelectionChange={(key) => setQuestId(key as Id<'quests'>)}
onSelectionChange={(key) => setQuestId(key as Id<"quests">)}
isRequired
className="w-full"
>
{quests?.map((quest) => {
const textValue = `${quest.title}${
quest.jurisdiction ? ` (${quest.jurisdiction})` : ''
}`
quest.jurisdiction ? ` (${quest.jurisdiction})` : ""
}`;

return (
<SelectItem key={quest._id} id={quest._id} textValue={textValue}>
{quest.title}{' '}
{quest.title}{" "}
{quest.jurisdiction && <Badge>{quest.jurisdiction}</Badge>}
</SelectItem>
)
);
})}
</ComboBox>
<FileTrigger
acceptedFileTypes={['application/pdf']}
acceptedFileTypes={["application/pdf"]}
onSelect={(e) => {
if (e === null) return
const files = Array.from(e)
setFile(files[0])
if (e === null) return;
const files = Array.from(e);
setFile(files[0]);
}}
>
<Button type="button" variant="secondary">
{file ? file.name : 'Select PDF'}
{file ? file.name : "Select PDF"}
</Button>
</FileTrigger>
<ModalFooter>
Expand All @@ -167,25 +167,25 @@ const NewDocumentModal = ({
</ModalFooter>
</Form>
</Modal>
)
}
);
};

const DocumentTableRow = ({
document,
}: {
document: DataModel['documents']['document']
document: DataModel["documents"]["document"];
}) => {
const formUrl = useQuery(api.documents.getURL, { documentId: document._id })
const softDelete = useMutation(api.documents.softDelete)
const undelete = useMutation(api.documents.undoSoftDelete)
const deleteForever = useMutation(api.documents.deleteForever)
const formUrl = useQuery(api.documents.getURL, { documentId: document._id });
const softDelete = useMutation(api.documents.softDelete);
const undelete = useMutation(api.documents.undoSoftDelete);
const deleteForever = useMutation(api.documents.deleteForever);

return (
<TableRow
key={document._id}
className="flex gap-2 items-center"
href={{
to: '/admin/documents/$documentId',
to: "/admin/documents/$documentId",
params: { documentId: document._id },
}}
>
Expand Down Expand Up @@ -240,12 +240,12 @@ const DocumentTableRow = ({
</MenuTrigger>
</TableCell>
</TableRow>
)
}
);
};

function DocumentsRoute() {
const [isNewFormModalOpen, setIsNewFormModalOpen] = useState(false)
const documents = useQuery(api.documents.getAll)
const [isNewFormModalOpen, setIsNewFormModalOpen] = useState(false);
const documents = useQuery(api.documents.getAll);

return (
<div>
Expand All @@ -272,7 +272,7 @@ function DocumentsRoute() {
title="No documents"
icon={FileText}
button={{
children: 'New Document',
children: "New Document",
onPress: () => setIsNewFormModalOpen(true),
}}
/>
Expand All @@ -289,5 +289,5 @@ function DocumentsRoute() {
onSubmit={() => setIsNewFormModalOpen(false)}
/>
</div>
)
);
}
Loading

0 comments on commit 76d663e

Please sign in to comment.