Compare commits
No commits in common. "main" and "tests" have entirely different histories.
|
@ -11,13 +11,12 @@ agent any
|
||||||
sh 'echo "DATABASE_URL=${DATABASE_URL}" | cat >> .env'
|
sh 'echo "DATABASE_URL=${DATABASE_URL}" | cat >> .env'
|
||||||
sh 'npm install'
|
sh 'npm install'
|
||||||
sh 'npm run build'
|
sh 'npm run build'
|
||||||
|
sh 'rm -r pack'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
stage('test'){
|
stage('test'){
|
||||||
steps{
|
steps{
|
||||||
sh 'npx playwright install'
|
|
||||||
sh 'npx playwright test'
|
sh 'npx playwright test'
|
||||||
sh 'rm -r pack'
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
stage('deploy'){
|
stage('deploy'){
|
||||||
|
@ -30,7 +29,6 @@ agent any
|
||||||
// Clean after build
|
// Clean after build
|
||||||
always {
|
always {
|
||||||
cleanWs(cleanWhenNotBuilt: true,
|
cleanWs(cleanWhenNotBuilt: true,
|
||||||
cleanWhenFailure: false,
|
|
||||||
deleteDirs: true,
|
deleteDirs: true,
|
||||||
disableDeferredWipeout: true,
|
disableDeferredWipeout: true,
|
||||||
// notFailBuild: true,
|
// notFailBuild: true,
|
||||||
|
|
BIN
prisma/dev.db
BIN
prisma/dev.db
Binary file not shown.
|
@ -44,7 +44,7 @@ export default function LoginForm() {
|
||||||
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<main className="flex flex-col items-center justify-around h-60 w-26">
|
<>
|
||||||
{submitted ? <div className="flex flex-col items-center justify-around h-30 w-26">
|
{submitted ? <div className="flex flex-col items-center justify-around h-30 w-26">
|
||||||
<h1>Logging in...</h1>
|
<h1>Logging in...</h1>
|
||||||
<Button asChild>
|
<Button asChild>
|
||||||
|
@ -52,7 +52,7 @@ export default function LoginForm() {
|
||||||
</Button>
|
</Button>
|
||||||
</div> :
|
</div> :
|
||||||
<Form {...form}>
|
<Form {...form}>
|
||||||
<form onSubmit={onSubmit} className="flex flex-col items-center space-y-6">
|
<form onSubmit={onSubmit} className="mt-20 flex flex-col items-center space-y-6">
|
||||||
<FormField
|
<FormField
|
||||||
control={form.control}
|
control={form.control}
|
||||||
name="email"
|
name="email"
|
||||||
|
@ -83,7 +83,7 @@ export default function LoginForm() {
|
||||||
</form>
|
</form>
|
||||||
</Form>
|
</Form>
|
||||||
}
|
}
|
||||||
</main>
|
</>
|
||||||
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,21 +3,21 @@ import { Button } from "@/components/ui/button";
|
||||||
|
|
||||||
export default function Home() {
|
export default function Home() {
|
||||||
return (
|
return (
|
||||||
<main className="flex flex-col gap-4 items-center justify-around h-60 w-26 m-6">
|
<main className="flex flex-col items-center justify-around h-60 w-26">
|
||||||
< div >
|
< div >
|
||||||
<h1 className="text-3xl font-black">
|
<h1 className="text-3xl font-black">
|
||||||
Welcome to Subman!
|
Welcome to Subman
|
||||||
</h1>
|
</h1>
|
||||||
</div >
|
</div >
|
||||||
<div className="flex flex-col gap-3">
|
<div>
|
||||||
<p>
|
<p className="mb-6">
|
||||||
This app is for demonstration purposes only. Data is reset periodically.
|
This app is for demonstration purposes only. Data is reset periodically.
|
||||||
</p>
|
</p>
|
||||||
<p>
|
<p>
|
||||||
<b>USERNAME:</b> demo@demo.demo
|
USERNAME: demo@demo.demo
|
||||||
</p>
|
</p>
|
||||||
<p>
|
<p>
|
||||||
<b>PASSWORD:</b> password
|
PASSWORD: password
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
<Button className="mt-6">
|
<Button className="mt-6">
|
||||||
|
|
|
@ -1,9 +1,12 @@
|
||||||
"use client"
|
"use client"
|
||||||
import { DialogHeader, DialogTitle, DialogFooter, DialogDescription } from "@/components/ui/dialog";
|
import { Dialog, DialogHeader, DialogTrigger, DialogContent, DialogClose, DialogTitle, DialogFooter, DialogDescription } from "@/components/ui/dialog";
|
||||||
import { Button } from "@/components/ui/button";
|
import { Button } from "@/components/ui/button";
|
||||||
import { ComponentProps } from "react";
|
import { ComponentProps } from "react";
|
||||||
import { Genre, Pub } from "@prisma/client";
|
import { Genre, Pub } from "@prisma/client";
|
||||||
|
import { createPub } from "app/lib/create";
|
||||||
import PubForm from "app/ui/forms/pub";
|
import PubForm from "app/ui/forms/pub";
|
||||||
|
import { Plus } from "lucide-react";
|
||||||
|
import { useState } from "react";
|
||||||
import { PubWithGenres } from "./page";
|
import { PubWithGenres } from "./page";
|
||||||
|
|
||||||
export default function EditPubDialog({ genres, closeDialog, defaults, dbAction }: ComponentProps<"div"> & { genres: Genre[], closeDialog: () => void, defaults: PubWithGenres, dbAction: (data: Pub & { genres: number[] }) => Promise<{ success: string }> }) {
|
export default function EditPubDialog({ genres, closeDialog, defaults, dbAction }: ComponentProps<"div"> & { genres: Genre[], closeDialog: () => void, defaults: PubWithGenres, dbAction: (data: Pub & { genres: number[] }) => Promise<{ success: string }> }) {
|
||||||
|
@ -14,7 +17,7 @@ export default function EditPubDialog({ genres, closeDialog, defaults, dbAction
|
||||||
<>
|
<>
|
||||||
<DialogHeader>
|
<DialogHeader>
|
||||||
<DialogTitle>Edit publication</DialogTitle>
|
<DialogTitle>Edit publication</DialogTitle>
|
||||||
<DialogDescription>Modify an entry for an existing publication. Remember - you can edit fields inline by double clicking on them!</DialogDescription>
|
<DialogDescription>Modify an entry for an existing publication.</DialogDescription>
|
||||||
</DialogHeader>
|
</DialogHeader>
|
||||||
<PubForm dbAction={dbAction} genres={genres} closeDialog={closeDialog} defaults={defaults} />
|
<PubForm dbAction={dbAction} genres={genres} closeDialog={closeDialog} defaults={defaults} />
|
||||||
<DialogFooter>
|
<DialogFooter>
|
||||||
|
|
|
@ -14,7 +14,7 @@ export default function EditStoryDialog({ genres, closeDialog, defaults, dbActio
|
||||||
<>
|
<>
|
||||||
<DialogHeader>
|
<DialogHeader>
|
||||||
<DialogTitle>Edit story</DialogTitle>
|
<DialogTitle>Edit story</DialogTitle>
|
||||||
<DialogDescription>Modify an entry for an existing story. Remember - you can edit fields inline by double-clicking on them!</DialogDescription>
|
<DialogDescription>Create an entry for a new story i.e. a thing you intend to submit for publication.</DialogDescription>
|
||||||
</DialogHeader>
|
</DialogHeader>
|
||||||
<StoryForm dbAction={dbAction} genres={genres} className="" closeDialog={closeDialog} defaults={defaults} />
|
<StoryForm dbAction={dbAction} genres={genres} className="" closeDialog={closeDialog} defaults={defaults} />
|
||||||
<DialogFooter>
|
<DialogFooter>
|
||||||
|
|
|
@ -5,6 +5,7 @@ import { Button } from "@/components/ui/button"
|
||||||
import { SubComplete } from "./page"
|
import { SubComplete } from "./page"
|
||||||
import { selectCol } from "app/ui/tables/selectColumn"
|
import { selectCol } from "app/ui/tables/selectColumn"
|
||||||
import TitleContainer from "app/ui/titleContainer"
|
import TitleContainer from "app/ui/titleContainer"
|
||||||
|
import { CalendarArrowUp } from "lucide"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -8,12 +8,10 @@ import { Pub, Response, Story } from "@prisma/client";
|
||||||
import SubmissionForm from "app/ui/forms/sub";
|
import SubmissionForm from "app/ui/forms/sub";
|
||||||
import { Plus } from "lucide-react";
|
import { Plus } from "lucide-react";
|
||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
import { StoryWithGenres } from "app/story/page";
|
|
||||||
import { PubWithGenres } from "app/publication/page";
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
export default function CreateSubmissionDialog({ stories, pubs, responses }: ComponentProps<"div"> & { stories: StoryWithGenres[], pubs: PubWithGenres[], responses: Response[] }) {
|
export default function CreateSubmissionDialog({ stories, pubs, responses }: ComponentProps<"div"> & { stories: Story[], pubs: Pub[], responses: Response[] }) {
|
||||||
|
|
||||||
const [isOpen, setIsOpen] = useState(false)
|
const [isOpen, setIsOpen] = useState(false)
|
||||||
function closeDialog() {
|
function closeDialog() {
|
||||||
|
|
|
@ -0,0 +1,22 @@
|
||||||
|
"use server"
|
||||||
|
import { getPubs, getResponses, getStories } from "app/lib/get";
|
||||||
|
import SubmissionForm from "app/ui/forms/sub";
|
||||||
|
import prisma from "app/lib/db";
|
||||||
|
import { CreateContainer, CreateContainerContent, CreateContainerHeader } from "app/ui/createContainer";
|
||||||
|
import { revalidatePath } from "next/cache";
|
||||||
|
import { redirect } from "next/navigation";
|
||||||
|
|
||||||
|
export default async function Page() {
|
||||||
|
const stories = await getStories()
|
||||||
|
const pubs = await getPubs()
|
||||||
|
const responses = await getResponses()
|
||||||
|
|
||||||
|
return (
|
||||||
|
<CreateContainer>
|
||||||
|
<CreateContainerHeader>New submission</CreateContainerHeader>
|
||||||
|
<CreateContainerContent>
|
||||||
|
<SubmissionForm stories={stories} pubs={pubs} responses={responses} />
|
||||||
|
</CreateContainerContent>
|
||||||
|
</CreateContainer>
|
||||||
|
)
|
||||||
|
}
|
|
@ -1,10 +1,8 @@
|
||||||
import { getGenres, getPubs, getPubsWithGenres, getResponses, getStories, getStoriesWithGenres, getSubsComplete } from "app/lib/get"
|
import { getGenres, getPubs, getResponses, getStories, getSubsComplete } from "app/lib/get"
|
||||||
import { DataTable } from "app/ui/tables/data-table"
|
import { DataTable } from "app/ui/tables/data-table"
|
||||||
import { columns } from "./columns"
|
import { columns } from "./columns"
|
||||||
import { Genre, Pub, Response, Story, Sub } from "@prisma/client"
|
import { Pub, Response, Story, Sub } from "@prisma/client"
|
||||||
import CreateSubmissionDialog from "./create"
|
import CreateSubmissionDialog from "./create"
|
||||||
import { PubWithGenres } from "app/publication/page"
|
|
||||||
import { StoryWithGenres } from "app/story/page"
|
|
||||||
|
|
||||||
export type SubComplete = Sub & {
|
export type SubComplete = Sub & {
|
||||||
pub: Pub,
|
pub: Pub,
|
||||||
|
@ -14,10 +12,10 @@ export type SubComplete = Sub & {
|
||||||
export default async function Page() {
|
export default async function Page() {
|
||||||
|
|
||||||
const subs: Array<SubComplete> = await getSubsComplete()
|
const subs: Array<SubComplete> = await getSubsComplete()
|
||||||
const stories: StoryWithGenres[] = await getStoriesWithGenres()
|
const stories = await getStories()
|
||||||
const pubs: PubWithGenres[] = await getPubsWithGenres()
|
const pubs = await getPubs()
|
||||||
const responses: Response[] = await getResponses()
|
const responses = await getResponses()
|
||||||
const genres: Genre[] = await getGenres()
|
const genres = await getGenres()
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="container px-1 md:px-4 mx-auto">
|
<div className="container px-1 md:px-4 mx-auto">
|
||||||
|
|
|
@ -706,10 +706,6 @@ body {
|
||||||
z-index: 100;
|
z-index: 100;
|
||||||
}
|
}
|
||||||
|
|
||||||
.m-6 {
|
|
||||||
margin: 1.5rem;
|
|
||||||
}
|
|
||||||
|
|
||||||
.m-auto {
|
.m-auto {
|
||||||
margin: auto;
|
margin: auto;
|
||||||
}
|
}
|
||||||
|
@ -719,11 +715,6 @@ body {
|
||||||
margin-right: -0.25rem;
|
margin-right: -0.25rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
.mx-0 {
|
|
||||||
margin-left: 0px;
|
|
||||||
margin-right: 0px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.mx-1 {
|
.mx-1 {
|
||||||
margin-left: 0.25rem;
|
margin-left: 0.25rem;
|
||||||
margin-right: 0.25rem;
|
margin-right: 0.25rem;
|
||||||
|
@ -774,6 +765,10 @@ body {
|
||||||
margin-top: 0.5rem;
|
margin-top: 0.5rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.mt-20 {
|
||||||
|
margin-top: 5rem;
|
||||||
|
}
|
||||||
|
|
||||||
.mt-3 {
|
.mt-3 {
|
||||||
margin-top: 0.75rem;
|
margin-top: 0.75rem;
|
||||||
}
|
}
|
||||||
|
@ -786,6 +781,10 @@ body {
|
||||||
margin-top: 1.5rem;
|
margin-top: 1.5rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.mb-6 {
|
||||||
|
margin-bottom: 1.5rem;
|
||||||
|
}
|
||||||
|
|
||||||
.block {
|
.block {
|
||||||
display: block;
|
display: block;
|
||||||
}
|
}
|
||||||
|
@ -855,10 +854,6 @@ body {
|
||||||
height: 1.25rem;
|
height: 1.25rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
.h-60 {
|
|
||||||
height: 15rem;
|
|
||||||
}
|
|
||||||
|
|
||||||
.h-7 {
|
.h-7 {
|
||||||
height: 1.75rem;
|
height: 1.75rem;
|
||||||
}
|
}
|
||||||
|
@ -892,6 +887,10 @@ body {
|
||||||
height: 100vh;
|
height: 100vh;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.h-60 {
|
||||||
|
height: 15rem;
|
||||||
|
}
|
||||||
|
|
||||||
.max-h-96 {
|
.max-h-96 {
|
||||||
max-height: 24rem;
|
max-height: 24rem;
|
||||||
}
|
}
|
||||||
|
@ -977,6 +976,14 @@ body {
|
||||||
width: 100vw;
|
width: 100vw;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.w-14 {
|
||||||
|
width: 3.5rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.w-20 {
|
||||||
|
width: 5rem;
|
||||||
|
}
|
||||||
|
|
||||||
.min-w-\[8rem\] {
|
.min-w-\[8rem\] {
|
||||||
min-width: 8rem;
|
min-width: 8rem;
|
||||||
}
|
}
|
||||||
|
@ -1134,6 +1141,10 @@ body {
|
||||||
justify-content: space-around;
|
justify-content: space-around;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.justify-items-center {
|
||||||
|
justify-items: center;
|
||||||
|
}
|
||||||
|
|
||||||
.gap-1 {
|
.gap-1 {
|
||||||
gap: 0.25rem;
|
gap: 0.25rem;
|
||||||
}
|
}
|
||||||
|
@ -1142,10 +1153,6 @@ body {
|
||||||
gap: 0.5rem;
|
gap: 0.5rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
.gap-3 {
|
|
||||||
gap: 0.75rem;
|
|
||||||
}
|
|
||||||
|
|
||||||
.gap-4 {
|
.gap-4 {
|
||||||
gap: 1rem;
|
gap: 1rem;
|
||||||
}
|
}
|
||||||
|
@ -1625,6 +1632,10 @@ body {
|
||||||
color: rgb(255 255 255 / var(--tw-text-opacity));
|
color: rgb(255 255 255 / var(--tw-text-opacity));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.underline {
|
||||||
|
text-decoration-line: underline;
|
||||||
|
}
|
||||||
|
|
||||||
.underline-offset-4 {
|
.underline-offset-4 {
|
||||||
text-underline-offset: 4px;
|
text-underline-offset: 4px;
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,14 +36,12 @@ import { createSub } from "app/lib/create"
|
||||||
import { subSchema } from "./schemas"
|
import { subSchema } from "./schemas"
|
||||||
import { useRouter } from "next/navigation"
|
import { useRouter } from "next/navigation"
|
||||||
import { Ban } from "lucide-react"
|
import { Ban } from "lucide-react"
|
||||||
import { Pub, Response, Story, Sub } from "@prisma/client"
|
import { Story } from "@prisma/client"
|
||||||
import { StoryWithGenres } from "app/story/page"
|
|
||||||
import { PubWithGenres } from "app/publication/page"
|
|
||||||
|
|
||||||
export type SubForm = z.infer<typeof subSchema>
|
export type SubForm = z.infer<typeof subSchema>
|
||||||
|
|
||||||
|
|
||||||
export default function SubmissionForm({ stories, pubs, responses, defaults, closeDialog }: { stories: StoryWithGenres[], pubs: PubWithGenres[], responses: Response[], defaults?: Sub, closeDialog?: () => void }) {
|
export default function SubmissionForm({ stories, pubs, responses, defaults, closeDialog }: { stories: any, pubs: any, responses: any, defaults?: any, closeDialog?: () => void }) {
|
||||||
const form = useForm<z.infer<typeof subSchema>>({
|
const form = useForm<z.infer<typeof subSchema>>({
|
||||||
resolver: zodResolver(subSchema),
|
resolver: zodResolver(subSchema),
|
||||||
defaultValues: {
|
defaultValues: {
|
||||||
|
@ -53,41 +51,19 @@ export default function SubmissionForm({ stories, pubs, responses, defaults, clo
|
||||||
})
|
})
|
||||||
const [isSubCalendarOpen, setIsSubCalendarOpen] = useState(false);
|
const [isSubCalendarOpen, setIsSubCalendarOpen] = useState(false);
|
||||||
const [isRespCalendarOpen, setIsRespCalendarOpen] = useState(false);
|
const [isRespCalendarOpen, setIsRespCalendarOpen] = useState(false);
|
||||||
const [relevantPubIds, setRelevantPubIds] = useState(pubs.map(e => e.id));
|
|
||||||
|
|
||||||
function updateRelevantPubs(storyId: number) {
|
|
||||||
console.log("storyId: " + storyId)
|
|
||||||
console.log("stories: ", stories)
|
|
||||||
const story = stories.find(e => e.id == storyId)
|
|
||||||
console.log("story: ", story)
|
|
||||||
const storyGenreIds = story?.genres.map(e => e.id) ?? []
|
|
||||||
const relevantPubIds = pubs.filter(e => {
|
|
||||||
const pubGenreIds = e.genres.map(e => e.id)
|
|
||||||
for (let i = 0; i < storyGenreIds.length; i++) {
|
|
||||||
const storyGenreId = storyGenreIds[i];
|
|
||||||
if (pubGenreIds.includes(storyGenreId)) return true
|
|
||||||
}
|
|
||||||
}).map(e => e.id)
|
|
||||||
console.log("relevant pubs: ", relevantPubIds)
|
|
||||||
setRelevantPubIds(relevantPubIds)
|
|
||||||
}
|
|
||||||
|
|
||||||
const storiesSelectItems = stories.map((e: Story) => (
|
const storiesSelectItems = stories.map((e: Story) => (
|
||||||
<SelectItem value={e.id?.toString()} key={e.title}>
|
<SelectItem value={e.id?.toString()} key={e.title}>
|
||||||
{e.title}
|
{e.title}
|
||||||
</SelectItem>
|
</SelectItem>
|
||||||
))
|
))
|
||||||
const pubsSelectItems = pubs.map(e => {
|
const pubsSelectItems = pubs.map(e => (
|
||||||
const isDisabled = !relevantPubIds.includes(e.id)
|
<SelectItem value={e.id} key={e.title}>
|
||||||
return (
|
{e.title}
|
||||||
<SelectItem disabled={isDisabled} value={e.id.toString()} key={e.title}>
|
</SelectItem>
|
||||||
{e.title}
|
))
|
||||||
</SelectItem>
|
|
||||||
)
|
|
||||||
})
|
|
||||||
|
|
||||||
const reponsesSelectItems = responses.map(e => (
|
const reponsesSelectItems = responses.map(e => (
|
||||||
<SelectItem value={e.id.toString()} key={e.response}>
|
<SelectItem value={e.id} key={e.title}>
|
||||||
{e.response}
|
{e.response}
|
||||||
</SelectItem>
|
</SelectItem>
|
||||||
))
|
))
|
||||||
|
@ -151,8 +127,7 @@ export default function SubmissionForm({ stories, pubs, responses, defaults, clo
|
||||||
render={({ field }) => (
|
render={({ field }) => (
|
||||||
<FormItem>
|
<FormItem>
|
||||||
<FormLabel className="text-sm md:text-base">Publication</FormLabel>
|
<FormLabel className="text-sm md:text-base">Publication</FormLabel>
|
||||||
<Select onOpenChange={() => updateRelevantPubs(form.getValues().storyId
|
<Select onValueChange={field.onChange} defaultValue={field.value?.toString()}>
|
||||||
)} onValueChange={field.onChange} defaultValue={field.value?.toString()}>
|
|
||||||
<FormControl>
|
<FormControl>
|
||||||
<SelectTrigger>
|
<SelectTrigger>
|
||||||
<SelectValue placeholder="Select something">
|
<SelectValue placeholder="Select something">
|
||||||
|
@ -164,7 +139,7 @@ export default function SubmissionForm({ stories, pubs, responses, defaults, clo
|
||||||
{pubsSelectItems}
|
{pubsSelectItems}
|
||||||
</SelectContent>
|
</SelectContent>
|
||||||
</Select>
|
</Select>
|
||||||
<FormDescription className="text-xs md:text-base">The market you sent it to. Bad genre fits are greyed out.</FormDescription>
|
<FormDescription className="text-xs md:text-base">The market you sent it to</FormDescription>
|
||||||
<FormMessage />
|
<FormMessage />
|
||||||
</FormItem>
|
</FormItem>
|
||||||
)}
|
)}
|
||||||
|
|
|
@ -2,6 +2,8 @@
|
||||||
import { Button } from "@/components/ui/button"
|
import { Button } from "@/components/ui/button"
|
||||||
import {
|
import {
|
||||||
ContextMenu,
|
ContextMenu,
|
||||||
|
ContextMenuContent,
|
||||||
|
ContextMenuItem,
|
||||||
ContextMenuTrigger,
|
ContextMenuTrigger,
|
||||||
} from "@/components/ui/context-menu"
|
} from "@/components/ui/context-menu"
|
||||||
import {
|
import {
|
||||||
|
@ -13,7 +15,7 @@ import {
|
||||||
DropdownMenuRadioGroup
|
DropdownMenuRadioGroup
|
||||||
} from "@/components/ui/dropdown-menu"
|
} from "@/components/ui/dropdown-menu"
|
||||||
import { Input } from "@/components/ui/input"
|
import { Input } from "@/components/ui/input"
|
||||||
import { ComponentProps, useState } from "react"
|
import { Component, ComponentProps, use, useState } from "react"
|
||||||
import {
|
import {
|
||||||
ColumnDef,
|
ColumnDef,
|
||||||
flexRender,
|
flexRender,
|
||||||
|
@ -36,7 +38,7 @@ import {
|
||||||
TableHeader,
|
TableHeader,
|
||||||
TableRow,
|
TableRow,
|
||||||
} from "@/components/ui/table"
|
} from "@/components/ui/table"
|
||||||
import { CircleHelp, EyeIcon, Filter, Trash2 } from "lucide-react"
|
import { EyeIcon, Trash2 } from "lucide-react"
|
||||||
import { usePathname, useSearchParams } from "next/navigation"
|
import { usePathname, useSearchParams } from "next/navigation"
|
||||||
import FormContextMenu from "./contextMenu"
|
import FormContextMenu from "./contextMenu"
|
||||||
import { deleteRecord, deleteRecords } from "app/lib/del"
|
import { deleteRecord, deleteRecords } from "app/lib/del"
|
||||||
|
@ -127,14 +129,16 @@ export function DataTable<TData, TValue>({
|
||||||
|
|
||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
|
|
||||||
const [filterBy, setFilterBy] = useState(table.getAllColumns().filter(e => e.getCanFilter())[0])
|
const [filterBy, setFilterBy] = useState(table.getAllColumns()[0])
|
||||||
const [isContextMenuOpen, setIsContextMenuOpen] = useState(false)
|
const [isContextMenuOpen, setIsContextMenuOpen] = useState(false)
|
||||||
return (<>
|
return (<>
|
||||||
<div className="flex gap-2 justify-between items-center py-1 md:py-4">
|
<div className="flex justify-between items-center py-1 md:py-4">
|
||||||
<div className="flex gap-1">
|
<div className="flex gap-2">
|
||||||
<DropdownMenu>
|
<DropdownMenu>
|
||||||
<DropdownMenuTrigger asChild>
|
<DropdownMenuTrigger asChild>
|
||||||
<Button variant="outline" className="mx-0"> <p className="hidden md:block">Filter by</p><Filter className="block md:hidden" /> </Button>
|
<Button variant="outline" className="hidden sm:block ml-auto">
|
||||||
|
Filter by
|
||||||
|
</Button>
|
||||||
</DropdownMenuTrigger>
|
</DropdownMenuTrigger>
|
||||||
<DropdownMenuContent align="end">
|
<DropdownMenuContent align="end">
|
||||||
{/*@ts-ignore*/}
|
{/*@ts-ignore*/}
|
||||||
|
@ -304,45 +308,36 @@ export function DataTable<TData, TValue>({
|
||||||
</TableHeader>
|
</TableHeader>
|
||||||
<TableBody>
|
<TableBody>
|
||||||
{table.getRowModel().rows?.length ? (
|
{table.getRowModel().rows?.length ? (
|
||||||
table.getRowModel().rows.map((row) => {
|
table.getRowModel().rows.map((row) => (
|
||||||
const classes = () => {
|
<ContextMenu key={row.id + "contextMenu"}>
|
||||||
const classes = []
|
<ContextMenuTrigger asChild>
|
||||||
if (row.getValue('response') === "Pending") classes.push("bg-accent")
|
<TableRow
|
||||||
if (row.getValue('response') === "Acceptance") classes.push("bg-primary")
|
key={row.id}
|
||||||
return classes.join(" ")
|
data-state={row.getIsSelected() && "selected"}
|
||||||
}
|
tabIndex={0}
|
||||||
return (
|
onDoubleClick={() => {
|
||||||
<ContextMenu key={row.id + "contextMenu"}>
|
if (tableName === "sub") {
|
||||||
<ContextMenuTrigger asChild>
|
openEditDialog(row)
|
||||||
<TableRow
|
|
||||||
key={row.id}
|
|
||||||
className={classes()}
|
|
||||||
data-state={row.getIsSelected() && "selected"}
|
|
||||||
tabIndex={0}
|
|
||||||
onDoubleClick={() => {
|
|
||||||
if (tableName === "sub") {
|
|
||||||
openEditDialog(row)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
>
|
}
|
||||||
{row.getVisibleCells().map((cell) => (
|
>
|
||||||
<TableCell key={cell.id}>
|
{row.getVisibleCells().map((cell) => (
|
||||||
{flexRender(cell.column.columnDef.cell, cell.getContext())}
|
<TableCell key={cell.id}>
|
||||||
</TableCell>
|
{flexRender(cell.column.columnDef.cell, cell.getContext())}
|
||||||
))}
|
</TableCell>
|
||||||
<FormContextMenu
|
))}
|
||||||
key={"formContextMenu" + row.id}
|
<FormContextMenu
|
||||||
row={row}
|
key={"formContextMenu" + row.id}
|
||||||
table={table}
|
row={row}
|
||||||
openEditDialog={openEditDialog}
|
table={table}
|
||||||
openDeleteDialog={openDeleteDialog}
|
openEditDialog={openEditDialog}
|
||||||
/>
|
openDeleteDialog={openDeleteDialog}
|
||||||
</TableRow>
|
/>
|
||||||
</ContextMenuTrigger>
|
</TableRow>
|
||||||
</ContextMenu>
|
</ContextMenuTrigger>
|
||||||
)
|
</ContextMenu>
|
||||||
})
|
))
|
||||||
) : (
|
) : (
|
||||||
<TableRow>
|
<TableRow>
|
||||||
<TableCell colSpan={columns.length} className="h-24 text-center">
|
<TableCell colSpan={columns.length} className="h-24 text-center">
|
||||||
|
|
|
@ -16,7 +16,7 @@ export const selectCol = {
|
||||||
|
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
enableColumnFilter: false,
|
|
||||||
cell: (props: CellContext<any, any>) => {
|
cell: (props: CellContext<any, any>) => {
|
||||||
return (
|
return (
|
||||||
<div className="flex items-start justify-left">
|
<div className="flex items-start justify-left">
|
||||||
|
|
Loading…
Reference in New Issue