Compare commits
2 Commits
bb601d3c82
...
75e5a95348
Author | SHA1 | Date |
---|---|---|
|
75e5a95348 | |
|
3b32316688 |
BIN
prisma/dev.db
BIN
prisma/dev.db
Binary file not shown.
|
@ -1,27 +1,24 @@
|
||||||
import { PrismaClient } from '@prisma/client'
|
import { PrismaClient } from "@prisma/client";
|
||||||
|
|
||||||
const prisma = new PrismaClient()
|
const prisma = new PrismaClient();
|
||||||
|
|
||||||
async function main() {
|
async function main() {
|
||||||
// ... you will write your Prisma Client queries here
|
// ... you will write your Prisma Client queries here
|
||||||
const story = await prisma.story.update({
|
const story = await prisma.story.update({
|
||||||
where: { id: 1 },
|
where: { id: 1 },
|
||||||
data: {
|
data: {
|
||||||
title: "Ghost Aliens of Mars",
|
title: "Ghost Aliens of Mars",
|
||||||
genres: { set: [{ id: 1 }, { id: 2 }], create: { name: "alien-punk" } }
|
genres: { set: [{ id: 1 }, { id: 2 }], create: { name: "alien-punk" } },
|
||||||
}
|
},
|
||||||
|
});
|
||||||
})
|
|
||||||
console.log(story)
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
main()
|
main()
|
||||||
.then(async () => {
|
.then(async () => {
|
||||||
await prisma.$disconnect()
|
await prisma.$disconnect();
|
||||||
})
|
})
|
||||||
.catch(async (e) => {
|
.catch(async (e) => {
|
||||||
console.error(e)
|
console.error(e);
|
||||||
await prisma.$disconnect()
|
await prisma.$disconnect();
|
||||||
process.exit(1)
|
process.exit(1);
|
||||||
})
|
});
|
||||||
|
|
|
@ -15,7 +15,6 @@ const dynamic = 'force-dynamic'
|
||||||
//POST endpoint
|
//POST endpoint
|
||||||
export async function POST(request: NextRequest) {
|
export async function POST(request: NextRequest) {
|
||||||
const body = await request.json()
|
const body = await request.json()
|
||||||
console.log(`body: ${JSON.stringify(body)}`)
|
|
||||||
const { email, password } = body
|
const { email, password } = body
|
||||||
|
|
||||||
if (!email || !password) {
|
if (!email || !password) {
|
||||||
|
|
|
@ -1,16 +1,12 @@
|
||||||
"use server"
|
"use server"
|
||||||
import { Genre, Pub, Story, Sub } from "@prisma/client"
|
import { Pub, Story, Sub } from "@prisma/client"
|
||||||
import prisma from "./db"
|
import prisma from "./db"
|
||||||
import { revalidatePath } from "next/cache"
|
import { revalidatePath } from "next/cache"
|
||||||
import { redirect } from "next/navigation"
|
|
||||||
import { z } from "zod"
|
import { z } from "zod"
|
||||||
import { storySchema } from "app/ui/forms/schemas"
|
|
||||||
import { pubSchema } from "app/ui/forms/schemas"
|
import { pubSchema } from "app/ui/forms/schemas"
|
||||||
import { subSchema } from "app/ui/forms/schemas"
|
import { subSchema } from "app/ui/forms/schemas"
|
||||||
import { prepGenreData, prepStoryData } from "./validate"
|
import { prepGenreData, prepStoryData } from "./validate"
|
||||||
import { SubForm } from "app/ui/forms/sub"
|
|
||||||
|
|
||||||
//TODO - data validation, error handling, unauthorized access handling
|
|
||||||
|
|
||||||
export async function createStory({ story, genres }: { story: Story, genres: number[] }): Promise<{ success: string }> {
|
export async function createStory({ story, genres }: { story: Story, genres: number[] }): Promise<{ success: string }> {
|
||||||
// will return undefined if middleware authorization fails
|
// will return undefined if middleware authorization fails
|
||||||
|
|
|
@ -0,0 +1,14 @@
|
||||||
|
import { Genre } from "@prisma/client";
|
||||||
|
import { FilterFn, Row } from "@tanstack/react-table";
|
||||||
|
|
||||||
|
export const genrePickerFilterFn = (row: Row<any>, columnId: string, filterValue: any) => {
|
||||||
|
|
||||||
|
const genres: Genre[] = row.getValue(columnId)
|
||||||
|
|
||||||
|
for (let index = 0; index < genres.length; index++) {
|
||||||
|
if (genres[genres.length - 1].name.includes(filterValue)) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
|
@ -18,7 +18,6 @@ export default function LoginForm() {
|
||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
const searchParams = useSearchParams()
|
const searchParams = useSearchParams()
|
||||||
const redirect = searchParams.get("from") ?? "/submission"
|
const redirect = searchParams.get("from") ?? "/submission"
|
||||||
console.log(redirect)
|
|
||||||
const form = useForm<z.infer<typeof loginSchema>>({
|
const form = useForm<z.infer<typeof loginSchema>>({
|
||||||
resolver: zodResolver(loginSchema),
|
resolver: zodResolver(loginSchema),
|
||||||
})
|
})
|
||||||
|
@ -37,6 +36,7 @@ export default function LoginForm() {
|
||||||
toast({ title: "login successful!" })
|
toast({ title: "login successful!" })
|
||||||
setSubmitted(true)
|
setSubmitted(true)
|
||||||
await revalidate(redirect)
|
await revalidate(redirect)
|
||||||
|
//BUG:the first time user logs in, page refreshes instead of redirecting
|
||||||
router.push(redirect)
|
router.push(redirect)
|
||||||
} else {
|
} else {
|
||||||
toast({ title: "login failed!" })
|
toast({ title: "login failed!" })
|
||||||
|
|
|
@ -8,6 +8,7 @@ import { selectCol } from "app/ui/tables/selectColumn"
|
||||||
import NumberInputCell from "app/ui/tables/inputs/numberInput"
|
import NumberInputCell from "app/ui/tables/inputs/numberInput"
|
||||||
import { pubSchema } from "app/ui/forms/schemas"
|
import { pubSchema } from "app/ui/forms/schemas"
|
||||||
import GenrePickerInputCell from "app/ui/tables/inputs/genrePickerInput"
|
import GenrePickerInputCell from "app/ui/tables/inputs/genrePickerInput"
|
||||||
|
import { genrePickerFilterFn } from "app/lib/filterFns"
|
||||||
|
|
||||||
|
|
||||||
const columnHelper = createColumnHelper<PubWithGenres>()
|
const columnHelper = createColumnHelper<PubWithGenres>()
|
||||||
|
@ -66,10 +67,10 @@ export const columns: ColumnDef<PubWithGenres>[] = [
|
||||||
</div>
|
</div>
|
||||||
),
|
),
|
||||||
cell: GenrePickerInputCell,
|
cell: GenrePickerInputCell,
|
||||||
filterFn: "arrIncludes"
|
filterFn: genrePickerFilterFn
|
||||||
//TODO - write custom filter function, to account for an array of objects
|
|
||||||
}),
|
}),
|
||||||
|
|
||||||
|
|
||||||
{
|
{
|
||||||
accessorKey: "query_after_days",
|
accessorKey: "query_after_days",
|
||||||
header: () => (
|
header: () => (
|
||||||
|
@ -78,6 +79,7 @@ export const columns: ColumnDef<PubWithGenres>[] = [
|
||||||
<span className="sm:hidden"><Clock /></span>
|
<span className="sm:hidden"><Clock /></span>
|
||||||
</div>
|
</div>
|
||||||
),
|
),
|
||||||
|
enableColumnFilter: false,
|
||||||
cell: cell => (
|
cell: cell => (
|
||||||
<>
|
<>
|
||||||
{/* @ts-ignore */}
|
{/* @ts-ignore */}
|
||||||
|
|
|
@ -8,6 +8,7 @@ import NumberInputCell from "app/ui/tables/inputs/numberInput"
|
||||||
import { storySchema } from "app/ui/forms/schemas"
|
import { storySchema } from "app/ui/forms/schemas"
|
||||||
import { TextInputCell } from "app/ui/tables/inputs/textInput"
|
import { TextInputCell } from "app/ui/tables/inputs/textInput"
|
||||||
import GenrePickerInputCell from "app/ui/tables/inputs/genrePickerInput"
|
import GenrePickerInputCell from "app/ui/tables/inputs/genrePickerInput"
|
||||||
|
import { genrePickerFilterFn } from "app/lib/filterFns"
|
||||||
const columnHelper = createColumnHelper<StoryWithGenres>()
|
const columnHelper = createColumnHelper<StoryWithGenres>()
|
||||||
|
|
||||||
export const columns: ColumnDef<StoryWithGenres>[] = [
|
export const columns: ColumnDef<StoryWithGenres>[] = [
|
||||||
|
@ -78,7 +79,7 @@ export const columns: ColumnDef<StoryWithGenres>[] = [
|
||||||
</div>
|
</div>
|
||||||
),
|
),
|
||||||
cell: GenrePickerInputCell,
|
cell: GenrePickerInputCell,
|
||||||
filterFn: "arrIncludes",
|
filterFn: genrePickerFilterFn,
|
||||||
meta: {}
|
meta: {}
|
||||||
}),
|
}),
|
||||||
|
|
||||||
|
|
|
@ -136,7 +136,7 @@ export function DataTable<TData, TValue>({
|
||||||
<div className="flex gap-2">
|
<div className="flex gap-2">
|
||||||
<DropdownMenu>
|
<DropdownMenu>
|
||||||
<DropdownMenuTrigger asChild>
|
<DropdownMenuTrigger asChild>
|
||||||
<Button variant="outline" className="hidden md:display-blockml-auto">
|
<Button variant="outline" className="hidden sm:block ml-auto">
|
||||||
Filter by
|
Filter by
|
||||||
</Button>
|
</Button>
|
||||||
</DropdownMenuTrigger>
|
</DropdownMenuTrigger>
|
||||||
|
|
Loading…
Reference in New Issue