(props: {
docPage: number;
setDocPage: React.Dispatch<React.SetStateAction<number>>;
isLastPage: boolean;
allDocumentCount: number;
docs: Document[];
setDocs: React.Dispatch<React.SetStateAction<Document[]>>;
supabase: SupabaseClient<Database>;
orgId: number;
editDocument: (document: Document) => void;
deleteDocument: (document: Document) => Promise<PostgrestError | null>;
})
| 200 | export const getServerSideProps = pageGetServerSideProps; |
| 201 | |
| 202 | function DocumentList(props: { |
| 203 | docPage: number; |
| 204 | setDocPage: React.Dispatch<React.SetStateAction<number>>; |
| 205 | isLastPage: boolean; |
| 206 | allDocumentCount: number; |
| 207 | docs: Document[]; |
| 208 | setDocs: React.Dispatch<React.SetStateAction<Document[]>>; |
| 209 | supabase: SupabaseClient<Database>; |
| 210 | orgId: number; |
| 211 | editDocument: (document: Document) => void; |
| 212 | deleteDocument: (document: Document) => Promise<PostgrestError | null>; |
| 213 | }) { |
| 214 | const [documentToDelete, setDocumentToDelete] = useState<Document | null>( |
| 215 | null, |
| 216 | ); |
| 217 | |
| 218 | const setDeleteDocumentModalOpen = (isOpen: boolean) => { |
| 219 | if (!isOpen) { |
| 220 | setDocumentToDelete(null); |
| 221 | } |
| 222 | }; |
| 223 | |
| 224 | const deleteDocument = async (document: Document) => { |
| 225 | const error = await props.deleteDocument(document); |
| 226 | if (error) { |
| 227 | console.error(error); |
| 228 | } else { |
| 229 | props.setDocs((currentDocs) => { |
| 230 | return currentDocs.filter( |
| 231 | (doc) => doc.docChunks[0].id !== document.docChunks[0].id, |
| 232 | ); |
| 233 | }); |
| 234 | } |
| 235 | setDocumentToDelete(null); |
| 236 | }; |
| 237 | |
| 238 | return ( |
| 239 | <> |
| 240 | <WarningModal |
| 241 | title={"Delete document?"} |
| 242 | description={"Are you sure you want to delete this document?"} |
| 243 | action={async () => { |
| 244 | if (documentToDelete) { |
| 245 | await deleteDocument(documentToDelete); |
| 246 | } |
| 247 | }} |
| 248 | actionColour={"red"} |
| 249 | actionName={"Delete"} |
| 250 | open={documentToDelete !== null} |
| 251 | setOpen={setDeleteDocumentModalOpen} |
| 252 | /> |
| 253 | |
| 254 | <div className="flex flex-col gap-y-2"> |
| 255 | <div className="flex w-full text-lg text-gray-300 gap-x-10 py-1 px-2 mb-1"> |
| 256 | <h3 className="flex-1">Page</h3> |
| 257 | <h3 className="w-40">Section</h3> |
| 258 | <h3 className="flex-1" /> |
| 259 | <h3 className="w-16" /> |
nothing calls this directly
no test coverage detected