This commit is contained in:
Malai Raja
2023-12-29 10:28:20 +05:30
parent 0fee281db0
commit 51e4ea978f
7 changed files with 75 additions and 4 deletions

View File

@@ -156,6 +156,7 @@ const Createorder = () => {
const [tenantinfo, setTenantinfo] = useState({});
const [searchword, setSearchword] = useState('');
const [clientdetailarr, setClientdetailarr] = useState([])
const [admintoken,setAdmintoken]=useState('');
useEffect(() => {
@@ -204,6 +205,24 @@ const Createorder = () => {
console.log(res)
if (res.data.status) {
setTenantinfo(res.data.details);
fetchadmintoken(res.data.details.partnerid)
}
setLoading(false)
}).catch((err) => {
console.log(err)
setLoading(false)
})
}
const fetchadmintoken = async (tid) => {
setLoading(true)
await axios.get(`${process.env.REACT_APP_URL}/partners/getadmintoken/?partnerid=${tid}`)
.then((res) => {
console.log(res)
if (res.data.status) {
// setTenantinfo(res.data.details);
setAdmintoken(res.data.details.userfcmtokem)
}
setLoading(false)
}).catch((err) => {
@@ -304,6 +323,11 @@ const Createorder = () => {
variant: 'success', anchorOrigin: { vertical: 'top', horizontal: 'right' },
autoHideDuration: 2000
})
if(admintoken){
notifyadmin(admintoken)
}
navigate('/orders')
} else {
opentoast(res.data.message)
@@ -461,6 +485,41 @@ const Createorder = () => {
}
}
const notifyadmin = async (id1) => {
setLoading(true)
await axios.post(`${process.env.REACT_APP_URL}/utils/notifyuser`, {
"sender": localStorage.getItem('firstname'),
"accessid": process.env.REACT_APP_RIDER_ACCESS_ID,
"notification": {
"priority": "high",
"to": id1,
"notification": {
"title": "Nearle Admin",
"body": "Orders has been placed for delivery.Kindly accept and process deliveries",
"sound": "ring"
}
}
})
.then((res) => {
console.log(res)
if (res.data.message == 'Success') {
enqueueSnackbar("Notification sent Successfully", {
variant: 'success', anchorOrigin: { vertical: 'top', horizontal: 'right' },
autoHideDuration: 2000
})
}
setLoading(false)
}).catch((err) => {
console.log(err)
enqueueSnackbar(err.message, {
variant: 'error', anchorOrigin: { vertical: 'top', horizontal: 'right' },
autoHideDuration: 2000
})
setLoading(false)
})
}