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

These are the complaints sent by players. You can answer them, and an email will be sent to the player so that he knows his complaint has been listened to.

{ adminInformationState.adminInformation?.complaints?.map(function(complaint, complaintIndex) { if (complaint.answered === "false") return (

By: {complaint.by}

Date: {new Date(complaint.date).toGMTString()}

{ adminInformationState.adminInformation.answeringComplaintIndex !== complaintIndex && }
{ adminInformationState.adminInformation.answeringComplaintIndex === complaintIndex && (

Your answer:

)}
)} )} { adminInformationState.adminInformation?.complaints?.map(function(complaint, complaintIndex) { if (complaint.answered === "true") return (

By: {complaint.by}

Date: {new Date(complaint.date).toGMTString()}

Answered

Your answer:

)} )}
) } export default Complaints