-
-
Notifications
You must be signed in to change notification settings - Fork 157
/
Copy pathSendSMS.tsx
117 lines (110 loc) · 2.9 KB
/
SendSMS.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
import {
Box,
Button,
Flex,
FormLabel,
Input,
Modal,
ModalBody,
ModalCloseButton,
ModalContent,
ModalFooter,
ModalHeader,
ModalOverlay,
Select,
Textarea,
useDisclosure,
useToast,
} from '@chakra-ui/react'
import { useState } from 'react'
import { useSelector } from 'react-redux'
import { sendSMSRequest } from '../../services'
import { selectDeviceList } from '../../store/deviceListReducer'
export default function SendSMS() {
const { isOpen, onOpen, onClose } = useDisclosure()
const deviceList = useSelector(selectDeviceList)
const toast = useToast()
const [formData, setFormData] = useState({
device: '',
receivers: '',
smsBody: '',
})
const handSend = (e) => {
e.preventDefault()
sendSMSRequest(formData.device, {
receivers: formData.receivers.replace(' ', '').split(','),
smsBody: formData.smsBody,
})
toast({
title: 'Sending SMS...',
})
onClose()
}
const handleChange = (e) => {
setFormData({
...formData,
[e.target.name]: e.target.value,
})
}
return (
<>
<Flex justifyContent='flex-end' marginBottom={20}>
<Button bg={'blue.400'} color={'white'} onClick={onOpen}>
Send SMS
</Button>
</Flex>
<Modal isOpen={isOpen} onClose={onClose}>
<ModalOverlay />
<ModalContent>
<ModalHeader>Send SMS</ModalHeader>
<ModalCloseButton />
<ModalBody>
<Box>
<FormLabel htmlFor='device'>Select Device</FormLabel>
<Select
id='device'
name='device'
placeholder='Select Device'
onChange={handleChange}
value={formData.smsBody}
>
{deviceList.data.map((device) => (
<option key={device._id} value={device._id}>
{device.model}
</option>
))}
</Select>
</Box>
<Box>
<FormLabel htmlFor='receivers'>Receiver</FormLabel>
<Input
placeholder='receiver'
name='receivers'
onChange={handleChange}
value={formData.receivers}
type='tel'
/>
</Box>
<Box>
<FormLabel htmlFor='smsBody'>SMS Body</FormLabel>
<Textarea
id='smsBody'
name='smsBody'
onChange={handleChange}
value={formData.smsBody}
/>
</Box>
</ModalBody>
<ModalFooter>
<Button variant='ghost' mr={3} onClick={onClose}>
Close
</Button>
<Button variant='outline' colorScheme='blue' onClick={handSend}>
Send
</Button>
</ModalFooter>
</ModalContent>
</Modal>
</>
)
}