refactor: reorganize imports and improve session handling in various components 🔨
Some checks are pending
Build and Push Docker Images / Build and Push Docker Images (push) Has started running

This commit is contained in:
2025-07-01 07:53:21 +05:00
parent 1549b209b3
commit a6d844e8d1
11 changed files with 121 additions and 143 deletions

View File

@ -43,7 +43,7 @@ export default function BlockDeviceDialog({
const onSubmit: SubmitHandler<z.infer<typeof validationSchema>> = (data) => {
setDisabled(true);
console.log("data in block device dialog", data);
console.log(data);
toast.promise(
blockDevice({
deviceId: String(device.id),
@ -58,9 +58,8 @@ export default function BlockDeviceDialog({
return "Blocked!";
},
error: (error) => {
console.error("Error blocking device:", error);
setDisabled(false);
return error.message || "Something went wrong";
return error || "Something went wrong";
},
},
);
@ -69,15 +68,15 @@ export default function BlockDeviceDialog({
return (
<div>
{device.blocked && !admin ? (
{device.blocked ? (
<Button
onClick={() => {
setDisabled(true);
toast.promise(
blockDevice({
blocked_by: "ADMIN",
blocked_by: "PARENT",
deviceId: String(device.id),
reason_for_blocking: "",
reason_for_blocking: ""
}),
{
loading: "unblockinig...",
@ -85,9 +84,9 @@ export default function BlockDeviceDialog({
setDisabled(false);
return "Unblocked!";
},
error: (error) => {
error: () => {
setDisabled(false);
return error.message || "Something went wrong";
return "Something went wrong";
},
},
);
@ -97,53 +96,83 @@ export default function BlockDeviceDialog({
</Button>
) : (
<div>
<Dialog open={open} onOpenChange={setOpen}>
<DialogTrigger asChild>
<Button disabled={disabled} variant="destructive">
<OctagonX />
Block
</Button>
</DialogTrigger>
<DialogContent className="sm:max-w-[425px]">
<DialogHeader>
<DialogTitle className="text-muted-foreground">
Reason for blocking this device 🚫
</DialogTitle>
</DialogHeader>
<form onSubmit={handleSubmit(onSubmit)}>
<div className="grid gap-2 py-2">
<div className="flex flex-col items-start gap-4">
<Label htmlFor="reason" className="text-right text-muted-foreground">
Reason for blocking
</Label>
<Textarea
rows={10}
{...register("reasonForBlocking")}
id="reasonForBlocking"
className={cn(
"col-span-5",
errors.reasonForBlocking && "ring-2 ring-red-500",
)}
/>
<span className="text-sm text-red-500">
{errors.reasonForBlocking?.message}
</span>
{!admin ? (
<Button
variant={"destructive"}
onClick={() => {
setDisabled(true);
toast.promise(
blockDevice({
blocked_by: "PARENT",
deviceId: String(device.id),
reason_for_blocking: "",
}),
{
loading: "blocking...",
success: () => {
setDisabled(false);
return "blocked!";
},
error: () => {
setDisabled(false);
return "Something went wrong";
},
},
);
}}
>
<OctagonX />
{disabled ? <TextShimmer>Blocking</TextShimmer> : "Block"}
</Button>
) : (
<Dialog open={open} onOpenChange={setOpen}>
<DialogTrigger asChild>
<Button disabled={disabled} variant="destructive">
<OctagonX />
Block
</Button>
</DialogTrigger>
<DialogContent className="sm:max-w-[425px]">
<DialogHeader>
<DialogTitle>
Please provide a reason for blocking this device.
</DialogTitle>
</DialogHeader>
<form onSubmit={handleSubmit(onSubmit)}>
<div className="grid gap-4 py-4">
<div className="flex flex-col items-start gap-1">
<Label htmlFor="reason" className="text-right">
Reason for blocking
</Label>
<Textarea
rows={10}
{...register("reasonForBlocking")}
id="reasonForBlocking"
className={cn(
"col-span-5",
errors.reasonForBlocking && "ring-2 ring-red-500",
)}
/>
<span className="text-sm text-red-500">
{errors.reasonForBlocking?.message}
</span>
</div>
</div>
</div>
<DialogFooter>
<Button
variant={"destructive"}
disabled={disabled}
type="submit"
>
Block
</Button>
</DialogFooter>
</form>
</DialogContent>
</Dialog>
<DialogFooter>
<Button
variant={"destructive"}
disabled={disabled}
type="submit"
>
Block
</Button>
</DialogFooter>
</form>
</DialogContent>
</Dialog>
)}
</div>
)}
</div>
);
}
}