From 621a5160025f567e60aec8423e60e41a541d97ce Mon Sep 17 00:00:00 2001 From: isra el Date: Sat, 8 Mar 2025 17:35:25 +0300 Subject: [PATCH 1/3] feat(web): auto select device if theres only 1 registered device in send sms section --- web/app/(app)/dashboard/(components)/send-sms.tsx | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/web/app/(app)/dashboard/(components)/send-sms.tsx b/web/app/(app)/dashboard/(components)/send-sms.tsx index 01d83ac..9067171 100644 --- a/web/app/(app)/dashboard/(components)/send-sms.tsx +++ b/web/app/(app)/dashboard/(components)/send-sms.tsx @@ -89,7 +89,15 @@ export default function SendSms() { name='deviceId' control={control} render={({ field }) => ( - From 2f0566c407006d044e3a62a9494596abc576f7aa Mon Sep 17 00:00:00 2001 From: isra el Date: Sat, 8 Mar 2025 17:53:55 +0300 Subject: [PATCH 2/3] feat(web): add reply popup feature to received sms messages --- .../dashboard/(components)/received-sms.tsx | 199 +++++++++++++++++- 1 file changed, 198 insertions(+), 1 deletion(-) diff --git a/web/app/(app)/dashboard/(components)/received-sms.tsx b/web/app/(app)/dashboard/(components)/received-sms.tsx index 3d4c5e6..5bee23f 100644 --- a/web/app/(app)/dashboard/(components)/received-sms.tsx +++ b/web/app/(app)/dashboard/(components)/received-sms.tsx @@ -4,8 +4,201 @@ import httpBrowserClient from '@/lib/httpBrowserClient' import { useQuery } from '@tanstack/react-query' import React, { useEffect, useState } from 'react' import { Card, CardContent } from '@/components/ui/card' -import { Clock } from 'lucide-react' +import { Clock, MessageSquare, Reply } from 'lucide-react' import { Skeleton } from '@/components/ui/skeleton' +import { Button } from '@/components/ui/button' +import { + Dialog, + DialogContent, + DialogDescription, + DialogHeader, + DialogTitle, + DialogTrigger, +} from '@/components/ui/dialog' +import { Input } from '@/components/ui/input' +import { Textarea } from '@/components/ui/textarea' +import { + Select, + SelectContent, + SelectItem, + SelectTrigger, + SelectValue, +} from '@/components/ui/select' +import { useForm, Controller } from 'react-hook-form' +import { zodResolver } from '@hookform/resolvers/zod' +import { sendSmsSchema } from '@/lib/schemas' +import type { SendSmsFormData } from '@/lib/schemas' +import { useMutation } from '@tanstack/react-query' +import { Spinner } from '@/components/ui/spinner' +import { Check, X } from 'lucide-react' + +function ReplyDialog({ sms, onClose }: { sms: any; onClose?: () => void }) { + const [open, setOpen] = useState(false) + + const { + mutate: sendSms, + isPending: isSendingSms, + error: sendSmsError, + isSuccess: isSendSmsSuccess, + } = useMutation({ + mutationKey: ['send-sms'], + mutationFn: (data: SendSmsFormData) => + httpBrowserClient.post(ApiEndpoints.gateway.sendSMS(data.deviceId), data), + onSuccess: () => { + setTimeout(() => { + setOpen(false) + if (onClose) onClose() + }, 1500) + }, + }) + + const { + register, + control, + handleSubmit, + formState: { errors }, + reset, + } = useForm({ + resolver: zodResolver(sendSmsSchema), + defaultValues: { + deviceId: sms?.device?._id, + recipients: [sms.sender], + message: '', + }, + }) + + const { data: devices, isLoading: isLoadingDevices } = useQuery({ + queryKey: ['devices'], + queryFn: () => + httpBrowserClient + .get(ApiEndpoints.gateway.listDevices()) + .then((res) => res.data), + }) + + useEffect(() => { + if (open) { + reset({ + deviceId: sms?.device?._id, + recipients: [sms.sender], + message: '', + }) + } + }, [open, sms, reset]) + + return ( + + + + + + + + + Reply to {sms.sender} + + + Send a reply message to this sender + + +
handleSubmit((data) => sendSms(data))(e)} + className='space-y-4 mt-4' + > +
+
+ ( + + )} + /> + {errors.deviceId && ( +

+ {errors.deviceId.message} +

+ )} +
+ +
+ + {errors.recipients?.[0] && ( +

+ {errors.recipients[0].message} +

+ )} +
+ +
+