|
| 1 | +import { |
| 2 | + Button, |
| 3 | + Flex, |
| 4 | + NumberDecrementStepper, |
| 5 | + NumberIncrementStepper, |
| 6 | + NumberInput, |
| 7 | + NumberInputField, |
| 8 | + NumberInputStepper, |
| 9 | + Text, |
| 10 | + useToast, |
| 11 | +} from "@chakra-ui/react"; |
| 12 | +import { useState } from "react"; |
| 13 | +import { trpc } from "../../utils/trpc"; |
| 14 | + |
| 15 | +/** Handles how long a student should wait before they can make another ticket */ |
| 16 | +const CoolDownTimer = () => { |
| 17 | + const [cooldownTime, setCooldownTime] = useState<number>(0); |
| 18 | + const setCooldownTimeMutation = trpc.admin.setCooldownTime.useMutation(); |
| 19 | + const toast = useToast(); |
| 20 | + |
| 21 | + trpc.admin.getCoolDownTime.useQuery(undefined, { |
| 22 | + refetchOnWindowFocus: false, |
| 23 | + onSuccess: (time) => { |
| 24 | + setCooldownTime(time); |
| 25 | + }, |
| 26 | + }); |
| 27 | + |
| 28 | + const handleSetCooldownTime = async () => { |
| 29 | + console.log(cooldownTime); |
| 30 | + await setCooldownTimeMutation.mutateAsync({ |
| 31 | + cooldownTime, |
| 32 | + }); |
| 33 | + |
| 34 | + toast({ |
| 35 | + title: "Success", |
| 36 | + description: "Cooldown time updated", |
| 37 | + status: "success", |
| 38 | + duration: 5000, |
| 39 | + position: "top-right", |
| 40 | + isClosable: true, |
| 41 | + }); |
| 42 | + }; |
| 43 | + |
| 44 | + return ( |
| 45 | + <Flex direction="column"> |
| 46 | + <Text fontSize="xl">Cooldown</Text> |
| 47 | + <Text fontSize="md"> |
| 48 | + Students must wait this many minutes since their last ticket was |
| 49 | + resolved to make another ticket |
| 50 | + </Text> |
| 51 | + <Flex flexDir="row"> |
| 52 | + <NumberInput |
| 53 | + value={cooldownTime} |
| 54 | + min={0} |
| 55 | + max={180} |
| 56 | + width="100%" |
| 57 | + onChange={(val) => setCooldownTime(parseInt(val))} |
| 58 | + > |
| 59 | + <NumberInputField /> |
| 60 | + <NumberInputStepper> |
| 61 | + <NumberIncrementStepper /> |
| 62 | + <NumberDecrementStepper /> |
| 63 | + </NumberInputStepper> |
| 64 | + </NumberInput> |
| 65 | + <Button colorScheme="telegram" onClick={handleSetCooldownTime}> |
| 66 | + Confirm |
| 67 | + </Button> |
| 68 | + </Flex> |
| 69 | + </Flex> |
| 70 | + ); |
| 71 | +}; |
| 72 | + |
| 73 | +export default CoolDownTimer; |
0 commit comments