-
Notifications
You must be signed in to change notification settings - Fork 0
Delete games #32
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Delete games #32
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,99 @@ | ||
| import { parseFormData, useForm } from '@rvf/react-router' | ||
| import { useState } from 'react' | ||
| import { ActionFunction, redirect, useFetcher } from 'react-router' | ||
| import z from 'zod' | ||
| import Modal from '~/components/Modal' | ||
| import { requireAuth } from '~/utils/requireAuth.server' | ||
| import { prisma } from '~/services/db.server' | ||
| import SubmitButton from '~/components/SubmitButton' | ||
|
|
||
| const schema = z.object({ | ||
| action: z.enum(['delete']) | ||
| }) | ||
|
|
||
| export const action: ActionFunction = async (args) => { | ||
| const { data } = await parseFormData(await args.request.formData(), schema) | ||
|
|
||
| const { userId } = await requireAuth(args) | ||
| const gameId = parseInt(args.params.game!, 10) | ||
|
|
||
| switch (data?.action) { | ||
| case 'delete': { | ||
| await prisma.game.delete({ | ||
| where: { | ||
| id: gameId, | ||
| userId: userId | ||
| } | ||
| }) | ||
|
|
||
| return redirect('/games') | ||
| } | ||
| } | ||
|
|
||
| throw new Response('Invalid action', { status: 400 }) | ||
|
727021 marked this conversation as resolved.
|
||
| } | ||
|
|
||
| const GameSettings = () => { | ||
| const [deleting, setDeleting] = useState(false) | ||
|
|
||
| const deleteFetcher = useFetcher() | ||
| const deleteForm = useForm({ | ||
| schema, | ||
| defaultValues: { action: 'delete' }, | ||
| fetcher: deleteFetcher, | ||
| method: 'POST' | ||
| }) | ||
|
|
||
| return ( | ||
| <> | ||
| <div className="flex flex-col flex-1 gap-2"> | ||
| <h2 className="m-0">Settings</h2> | ||
| <div className="w-2xl max-w-full no-underline border rounded-xs p-2"> | ||
| <div className="flex flex-col min-[400px]:flex-row gap-4 justify-between"> | ||
| <div className="flex flex-col"> | ||
| <h4 className="m-0 text-error">Delete Game</h4> | ||
| <p className="text-sm text-error m-0 whitespace-pre-wrap"> | ||
| This will permanently delete the game and all associated data. | ||
| This action cannot be undone. | ||
| </p> | ||
| </div> | ||
| <button | ||
| className="btn btn-outline btn-error btn-sm self-end" | ||
| onClick={() => setDeleting(true)} | ||
| > | ||
| Delete | ||
| </button> | ||
| </div> | ||
| </div> | ||
| </div> | ||
| <Modal open={deleting} onClose={() => setDeleting(false)}> | ||
| <form {...deleteForm.getFormProps()} className="flex flex-col gap-4"> | ||
| <input {...deleteForm.getHiddenInputProps('action')} /> | ||
| <h3 className="m-0">Confirm Deletion</h3> | ||
| <p className="text-sm"> | ||
| Are you sure you want to delete this game? This action cannot be | ||
| undone. | ||
| </p> | ||
| <div className="flex justify-end gap-2"> | ||
| <button | ||
| className="btn btn-ghost" | ||
| type="button" | ||
| onClick={() => setDeleting(false)} | ||
| > | ||
| Cancel | ||
| </button> | ||
| <SubmitButton | ||
| className="btn btn-outline btn-error" | ||
| formApi={deleteForm} | ||
| fetcher={deleteFetcher} | ||
| > | ||
| Delete Game | ||
| </SubmitButton> | ||
| </div> | ||
| </form> | ||
| </Modal> | ||
| </> | ||
| ) | ||
| } | ||
|
|
||
| export default GameSettings | ||
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.