import React from 'react' import { useEffect } from 'react'; import { useSelector, useDispatch } from 'react-redux' import axios from 'axios'; import { setAdminInformation } from '../../redux/reducers/adminInformationSlice'; import { setAdmin } from '../../redux/reducers/adminSlice'; import { setStyle } from '../../redux/reducers/styleSlice'; const Complaints = () => { const dispatch = useDispatch(); const styleState = useSelector(state => state.style); const adminState = useSelector(state => state.admin); const adminInformationState = useSelector(state => state.adminInformation); useEffect(() => { axios.get(`/api/postgre?action=get_complaints_as_admin&admin_id=${localStorage.CAESSINO_ADMIN_ID}`).then(res => { if (res.data?.success) { dispatch(setAdminInformation({ ...adminInformationState.adminInformation, complaints: res.data?.complaints, })) } }) }, []) function hideComplaintsScreen() { dispatch(setAdmin({ ...adminState.admin, displays: { ...adminState.admin.displays, complaintsScreen: false, } })) } function answerComplaint(idx) { dispatch(setAdminInformation({ ...adminInformationState.adminInformation, answeringComplaintIndex: idx, answerForComplaint: '', })) } function sendAnswer(complaint) { axios.post(`/api/postgre`, { action: 'send_complaint_answer_as_admin', admin_id: localStorage.CAESSINO_ADMIN_ID, complaint: { ...complaint, answer: adminInformationState.adminInformation.answerForComplaint, } }).then(res => { if (res.data?.success) { dispatch(setAdminInformation({ ...adminInformationState.adminInformation, complaints: res.data?.complaints, answerForComplaint: '', })) dispatch(setStyle({ ...styleState.style, notification: { show: true, text: 'Answer sent successfully', status: 'success', }, })) } }); } function onChangeAnswer(e) { dispatch(setAdminInformation({ ...adminInformationState.adminInformation, answerForComplaint: e.target.value, })) } return (
hideComplaintsScreen()}>⬅ Go Back
By: {complaint.by}
Date: {new Date(complaint.date).toGMTString()}
Your answer:
By: {complaint.by}
Date: {new Date(complaint.date).toGMTString()}
Answered
Your answer: