2025-08-04 12:04:33 -07:00
|
|
|
import Widget from "./Widget";
|
2026-01-30 19:11:11 +00:00
|
|
|
import { Stack, Box, Field, Input, Button, Text, Flex } from "@chakra-ui/react";
|
2025-08-05 17:12:59 -07:00
|
|
|
import { useForm } from "react-hook-form";
|
2025-08-06 16:27:08 -07:00
|
|
|
import { useState } from "react";
|
2025-08-11 12:59:38 -07:00
|
|
|
import { LuAsterisk } from "react-icons/lu";
|
2025-08-04 12:04:33 -07:00
|
|
|
|
|
|
|
|
export default function AlertLevel({id, isEditable, isDelete, DeleteWidget}) {
|
2025-08-11 12:59:38 -07:00
|
|
|
const { register, handleSubmit, reset, formState: {errors} } = useForm();
|
2025-08-06 16:27:08 -07:00
|
|
|
const onSubmit = (data) => {
|
2025-08-11 12:59:38 -07:00
|
|
|
console.log("data: ", data);
|
|
|
|
|
if (data.volcanoname === '') {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
2025-08-06 16:27:08 -07:00
|
|
|
setIsSubmit(true);
|
2025-08-11 12:59:38 -07:00
|
|
|
reset();
|
2025-08-06 16:27:08 -07:00
|
|
|
}
|
|
|
|
|
const [isSubmit, setIsSubmit] = useState(false);
|
2025-08-05 17:12:59 -07:00
|
|
|
|
2025-08-06 16:27:08 -07:00
|
|
|
// Prop Forwarding
|
|
|
|
|
const widgetProps = { id, isEditable, isDelete, DeleteWidget, isSubmit, setIsSubmit }
|
2025-08-04 12:04:33 -07:00
|
|
|
return (
|
2025-08-06 16:27:08 -07:00
|
|
|
<Widget title="Alert Level" {...widgetProps}>
|
|
|
|
|
{!isSubmit ? (
|
2025-08-11 12:59:38 -07:00
|
|
|
// DISPLAYING INPUT FIElDS AND LABELS
|
2025-08-06 16:27:08 -07:00
|
|
|
<Box
|
|
|
|
|
as="form"
|
|
|
|
|
onSubmit={handleSubmit(onSubmit)}
|
|
|
|
|
width="100%"
|
|
|
|
|
height="100%"
|
|
|
|
|
pt={1}
|
|
|
|
|
pl={3}
|
|
|
|
|
pr={3}
|
|
|
|
|
display="flex"
|
|
|
|
|
flexDir="column"
|
2026-01-30 19:11:11 +00:00
|
|
|
gap="10"
|
2025-08-06 16:27:08 -07:00
|
|
|
>
|
2025-08-11 12:59:38 -07:00
|
|
|
<Field.Root orientation="horizontal">
|
2025-08-06 16:27:08 -07:00
|
|
|
<Stack direction="column" gap="3" width="100%">
|
2025-08-11 12:59:38 -07:00
|
|
|
<Stack direction="row" width="100%">
|
2025-08-06 16:27:08 -07:00
|
|
|
<Field.Label whiteSpace="nowrap" fontWeight="bold">Country Name</Field.Label>
|
2025-08-11 12:59:38 -07:00
|
|
|
{/* place select drop down menu here instead of asking for input */}
|
2025-08-06 16:27:08 -07:00
|
|
|
<Input {...register("countryname")} placeholder="Enter country name"/>
|
|
|
|
|
</Stack>
|
2025-08-11 12:59:38 -07:00
|
|
|
<Flex position="relative" dir="column" gap="0.5" width="100%">
|
|
|
|
|
<Stack direction="row" width="100%">
|
|
|
|
|
<Field.Label display="flex" whiteSpace="nowrap" fontWeight="bold">
|
|
|
|
|
Volcano Name <LuAsterisk color="tomato" />
|
|
|
|
|
</Field.Label>
|
|
|
|
|
<Input
|
|
|
|
|
border={errors.volcanoname ? "2px solid" : undefined}
|
|
|
|
|
borderColor={errors.volcanoname ? "tomato" : undefined}
|
|
|
|
|
{...register("volcanoname", { required: 'This field is required.' })}
|
|
|
|
|
placeholder="Enter volcano name"/>
|
|
|
|
|
</Stack>
|
|
|
|
|
{errors.volcanoname && <Box cursor="default" userSelect="none" position="absolute" top="40px" left="8.5rem" style={{ color: 'tomato' }}>{errors.volcanoname.message}</Box>}
|
|
|
|
|
</Flex>
|
2025-08-06 16:27:08 -07:00
|
|
|
</Stack>
|
|
|
|
|
</Field.Root>
|
2026-01-30 19:11:11 +00:00
|
|
|
<Button type="submit" size="sm">Submit</Button>
|
2025-08-06 16:27:08 -07:00
|
|
|
</Box>
|
|
|
|
|
):(
|
2025-08-11 12:59:38 -07:00
|
|
|
// DISPLAYING ALERT LEVEL DATA
|
2025-08-06 16:27:08 -07:00
|
|
|
<Box p={1} mt={1} ml="auto" mr="auto" width="200px">
|
|
|
|
|
<Box
|
|
|
|
|
bg="bg"
|
|
|
|
|
shadow="md"
|
|
|
|
|
borderRadius="md"
|
|
|
|
|
p={8}
|
|
|
|
|
width="200px"
|
|
|
|
|
height="10px"
|
|
|
|
|
textAlign="center"
|
|
|
|
|
display="flex"
|
|
|
|
|
alignItems="center"
|
|
|
|
|
justifyContent="center"
|
|
|
|
|
>
|
|
|
|
|
<Text fontsize="2xl" fontWeight="bold" color="gray.700">Alert Level Data Coming Soon.</Text>
|
|
|
|
|
</Box>
|
|
|
|
|
</Box>
|
|
|
|
|
)}
|
2025-08-04 12:04:33 -07:00
|
|
|
</Widget>
|
|
|
|
|
);
|
|
|
|
|
}
|