-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
cfd2342
commit 42a8a69
Showing
11 changed files
with
210 additions
and
189 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 |
---|---|---|
@@ -0,0 +1,73 @@ | ||
import { Button, Dialog, styled, TextField } from '@takaro/lib-components'; | ||
import { FC } from 'react'; | ||
import { useForm, SubmitHandler } from 'react-hook-form'; | ||
import { z } from 'zod'; | ||
import { zodResolver } from '@hookform/resolvers/zod'; | ||
import { useTeleportPlayer } from 'queries/gameserver'; | ||
|
||
const Container = styled.div` | ||
display: grid; | ||
grid-template-columns: 1fr 1fr 1fr; | ||
gap: ${({ theme }) => theme.spacing[1]}; | ||
`; | ||
|
||
interface TeleportPlayerDialogProps { | ||
gameServerId: string; | ||
playerId: string; | ||
open: boolean; | ||
setOpen: (open: boolean) => void; | ||
} | ||
|
||
export const TeleportPlayerDialog: FC<TeleportPlayerDialogProps> = ({ gameServerId, playerId, open, setOpen }) => { | ||
const onSuccess = () => { | ||
setOpen(false); | ||
}; | ||
|
||
return ( | ||
<Dialog open={open} onOpenChange={setOpen}> | ||
<Dialog.Content> | ||
<Dialog.Heading> | ||
<strong>Teleport player:</strong> | ||
</Dialog.Heading> | ||
<Dialog.Body> | ||
<TeleportPlayerForm gameServerId={gameServerId} playerId={playerId} onSuccess={onSuccess} /> | ||
</Dialog.Body> | ||
</Dialog.Content> | ||
</Dialog> | ||
); | ||
}; | ||
|
||
interface TeleportPlayerForm { | ||
playerId: string; | ||
gameServerId: string; | ||
onSuccess: () => void; | ||
} | ||
const TeleportPlayerForm: FC<TeleportPlayerForm> = ({ gameServerId, playerId, onSuccess }) => { | ||
const validationSchema = z.object({ | ||
x: z.number(), | ||
y: z.number(), | ||
z: z.number(), | ||
}); | ||
const { control, handleSubmit } = useForm<z.infer<typeof validationSchema>>({ | ||
resolver: zodResolver(validationSchema), | ||
}); | ||
|
||
const onSubmit: SubmitHandler<z.infer<typeof validationSchema>> = ({ x, y, z }) => { | ||
const { mutate } = useTeleportPlayer(); | ||
try { | ||
mutate({ playerId, gameServerId, x, y, z }); | ||
onSuccess(); | ||
} catch { } | ||
Check failure on line 60 in packages/web-main/src/components/TeleportPlayerDialog.tsx GitHub Actions / Run Prettier and Commit Changes
Check failure on line 60 in packages/web-main/src/components/TeleportPlayerDialog.tsx GitHub Actions / node-ci (20)
|
||
}; | ||
|
||
return ( | ||
<form onSubmit={handleSubmit(onSubmit)}> | ||
<Container> | ||
<TextField type="number" label="X coordinate" name="x" control={control} placeholder="100" /> | ||
<TextField type="number" label="Y coordinate" name="y" control={control} placeholder="100" /> | ||
<TextField type="number" label="Z coordinate" name="z" control={control} placeholder="100" /> | ||
</Container> | ||
<Button type="submit" fullWidth text="Teleport player" /> | ||
</form> | ||
); | ||
}; |
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
Oops, something went wrong.