-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[BDGR-85] Add buttons to edit/delete show (#682)
* [BDGR-85] Add buttons to edit/delete show * Rogue TODO * Update tests (and sr-only text) * more test updates * Add playwright/.auth to gitignore
- Loading branch information
1 parent
89949ba
commit 31edef0
Showing
13 changed files
with
203 additions
and
11 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,3 +12,4 @@ node_modules/ | |
|
||
coverage/ | ||
*/coverage/ | ||
playwright/.auth/ |
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,36 @@ | ||
"use client"; | ||
|
||
import { | ||
Popover, | ||
PopoverTrigger, | ||
PopoverContent, | ||
} from "@badger/components/popover"; | ||
import { useTransition } from "react"; | ||
import { deletShow } from "./actions"; | ||
import Button from "@badger/components/button"; | ||
|
||
export function ShowDeletButton(props: { showID: number }) { | ||
const [isPending, startTransition] = useTransition(); | ||
return ( | ||
<Popover> | ||
<PopoverTrigger asChild> | ||
<Button color="danger"> | ||
Delet <span className="sr-only">Show</span> | ||
</Button> | ||
</PopoverTrigger> | ||
<PopoverContent> | ||
<Button | ||
color="danger" | ||
onClick={() => { | ||
startTransition(async () => { | ||
await deletShow(props.showID); | ||
}); | ||
}} | ||
disabled={isPending} | ||
> | ||
You sure boss? | ||
</Button> | ||
</PopoverContent> | ||
</Popover> | ||
); | ||
} |
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
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,29 @@ | ||
"use server"; | ||
|
||
import { schema } from "./schema"; | ||
import { revalidatePath } from "next/cache"; | ||
import { db } from "@/lib/db"; | ||
import { FormResponse } from "@/components/Form"; | ||
import { zodErrorResponse } from "@/components/FormServerHelpers"; | ||
import { z } from "zod"; | ||
import { requirePermission } from "@/lib/auth"; | ||
|
||
export async function doEdit( | ||
data: z.infer<typeof schema>, | ||
): Promise<FormResponse> { | ||
await requirePermission("ManageShows"); | ||
const result = schema.safeParse(data); | ||
if (!result.success) { | ||
return zodErrorResponse(result.error); | ||
} | ||
const res = await db.show.update({ | ||
where: { id: result.data.id }, | ||
data: { | ||
name: result.data.name, | ||
start: result.data.start, | ||
}, | ||
}); | ||
revalidatePath(`/`); | ||
revalidatePath(`/shows/${res.id}`); | ||
return { ok: true, id: res.id }; | ||
} |
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,35 @@ | ||
"use client"; | ||
|
||
import { Show } from "@badger/prisma/client"; | ||
import { schema } from "./schema"; | ||
import { DatePickerField, Field, HiddenField } from "@/components/FormFields"; | ||
import { doEdit } from "./actions"; | ||
import Form from "@/components/Form"; | ||
import { useRouter } from "next/navigation"; | ||
|
||
export function EditShowForm(props: { initialValues: Show }) { | ||
const router = useRouter(); | ||
return ( | ||
<div> | ||
<h1 className="text-4xl">Edit '{props.initialValues.name}'</h1> | ||
<Form | ||
action={doEdit} | ||
schema={schema} | ||
initialValues={props.initialValues} | ||
onSuccess={(v) => { | ||
router.push(`/shows/${v.id}`); | ||
}} | ||
submitLabel="Save" | ||
> | ||
<HiddenField name="id" value={props.initialValues.id.toString(10)} /> | ||
<Field name="name" label="Name" /> | ||
<DatePickerField | ||
name="start" | ||
label="Start" | ||
showTimeSelect | ||
timeIntervals={15} | ||
/> | ||
</Form> | ||
</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,22 @@ | ||
import { requirePermission } from "@/lib/auth"; | ||
import { db } from "@/lib/db"; | ||
import { notFound } from "next/navigation"; | ||
import { EditShowForm } from "./form"; | ||
|
||
export default async function EditShowDetailsForm({ | ||
params, | ||
}: { | ||
params: { show_id: string }; | ||
}) { | ||
await requirePermission("ManageShows"); | ||
const show = await db.show.findFirst({ | ||
where: { | ||
id: parseInt(params.show_id, 10), | ||
}, | ||
}); | ||
if (!show) { | ||
notFound(); | ||
} | ||
|
||
return <EditShowForm initialValues={show} />; | ||
} |
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,10 @@ | ||
import { z } from "zod"; | ||
import { zfd } from "zod-form-data"; | ||
|
||
export const dateFormat = "YYYY-MM-DD HH:mm"; | ||
|
||
export const schema = zfd.formData({ | ||
id: z.coerce.number().int(), | ||
name: z.string(), | ||
start: z.coerce.date(), | ||
}); |
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
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
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