@@ -134,7 +178,7 @@ function ReplyDialog({ sms, onClose }: { sms: any; onClose?: () => void }) {
- {devices?.data?.map((device) => (
+ {devices?.data?.map((device: any) => (
{device.brand} {device.model}{' '}
{device.enabled ? '' : '(disabled)'}
@@ -150,7 +194,6 @@ function ReplyDialog({ sms, onClose }: { sms: any; onClose?: () => void }) {
)}
-
@@ -212,30 +240,27 @@ function ReplyDialog({ sms, onClose }: { sms: any; onClose?: () => void }) {
)
}
-function FollowUpDialog({
- message,
- onClose,
-}: {
- message: any
- onClose?: () => void
-}) {
- const [open, setOpen] = useState(false)
-
+function FollowUpDialog({ message, onClose, open, onOpenChange }: { message: any; onClose?: () => void; open: boolean; onOpenChange: (open: boolean) => void }) {
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: () => {
+ toast.success('Follow-up SMS sent successfully!')
setTimeout(() => {
- setOpen(false)
+ onOpenChange(false)
if (onClose) onClose()
}, 1500)
},
+ onError: (error: any) => {
+ toast.error('Failed to send follow-up SMS.', {
+ description: error.response?.data?.message || 'Please try again.',
+ })
+ },
})
const {
@@ -250,19 +275,16 @@ function FollowUpDialog({
deviceId: message?.device?._id,
recipients: [
message.recipient ||
- (message.recipients && message.recipients[0]) ||
- '',
+ (message.recipients && message.recipients[0]) ||
+ '',
],
message: '',
},
})
- const { data: devices, isLoading: isLoadingDevices } = useQuery({
+ const { data: devices } = useQuery({
queryKey: ['devices'],
- queryFn: () =>
- httpBrowserClient
- .get(ApiEndpoints.gateway.listDevices())
- .then((res) => res.data),
+ queryFn: () => httpBrowserClient.get(ApiEndpoints.gateway.listDevices()).then((res) => res.data),
})
useEffect(() => {
@@ -271,8 +293,8 @@ function FollowUpDialog({
deviceId: message?.device?._id,
recipients: [
message.recipient ||
- (message.recipients && message.recipients[0]) ||
- '',
+ (message.recipients && message.recipients[0]) ||
+ '',
],
message: '',
})
@@ -280,13 +302,7 @@ function FollowUpDialog({
}, [open, message, reset])
return (
-