-
Notifications
You must be signed in to change notification settings - Fork 320
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'HITK-TECH-Community:main' into main
- Loading branch information
Showing
6 changed files
with
279 additions
and
113 deletions.
There are no files selected for viewing
125 changes: 125 additions & 0 deletions
125
frontend/src/pages/Admin/Components/Faq/Q&A/AnswersModel/AnswersModel.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
import React, { useEffect, useState } from "react"; | ||
import { Modal, Backdrop, Fade } from '@material-ui/core'; | ||
import { SimpleToast } from "../../../../../../components/util/Toast"; | ||
import { getAnswers, updateAnswerStatus, deleteAnswer } from "../../../../../../service/Faq"; | ||
import style from './AnswersModel.scss' | ||
|
||
export function AnswersModel(props) { | ||
let dark = props.theme | ||
const [answers, setAnswers] = useState([]) | ||
const [toast, setToast] = useState({ | ||
toastStatus: false, | ||
toastType: "", | ||
toastMessage: "", | ||
}); | ||
async function fetchAnswers() { | ||
const data = await getAnswers(props.data._id, setToast) | ||
setAnswers(data) | ||
} | ||
const updateAnswer = async (id, status) => { | ||
setToast({ toastStatus: true, toastMessage: "Loading...", toastType: "info" }) | ||
await updateAnswerStatus(id, status, setToast); | ||
fetchAnswers() | ||
} | ||
const handleDeleteAnswer = async (answerId) => { | ||
setToast({ toastStatus: true, toastMessage: "Loading...", toastType: "info" }) | ||
await deleteAnswer(answerId, setToast) | ||
fetchAnswers() | ||
} | ||
useEffect(() => { | ||
if (props.open) | ||
fetchAnswers() | ||
}, [props]) | ||
function timeStampFormatter(time) { | ||
const months = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"] | ||
const messageTime = new Date(time) | ||
return `${String(messageTime.getDate())} ${String(months[messageTime.getMonth()])} ${String(messageTime.getFullYear())}` | ||
} | ||
return ( | ||
<div> | ||
{toast.toastStatus && ( | ||
<SimpleToast | ||
open={toast.toastStatus} | ||
message={toast.toastMessage} | ||
handleCloseToast={() => { setToast({ toastMessage: "", toastStatus: false, toastType: "" }) }} | ||
severity={toast.toastType} | ||
/> | ||
)} | ||
<Modal | ||
aria-labelledby="transition-modal-title" | ||
aria-describedby="transition-modal-description" | ||
className="modal" | ||
open={props.open} | ||
onClose={props.handleClose} | ||
closeAfterTransition | ||
BackdropComponent={Backdrop} | ||
BackdropProps={{ | ||
timeout: 500, | ||
}} | ||
> | ||
<Fade in={props.open}> | ||
<div className={"modal-container"} style={{ background: dark ? "#171717" : "white" }}> | ||
<div className="close-icon-container"> | ||
<span onClick={() => { | ||
setToast({ toastMessage: "", toastStatus: false, toastType: "" }) | ||
props.handleClose(false) | ||
}}> | ||
<i class="fas fa-times close-icon" style={{ color: dark && "white" }}></i> | ||
</span> | ||
</div> | ||
{ | ||
answers.length == 0 ? | ||
<p style={{ color: dark && "white" }}>No answers found...</p> | ||
: | ||
<div> | ||
{ | ||
answers.map((ans, index) => { | ||
return ( | ||
<div className="answer-container" style={{ color: dark && "white" }}> | ||
<div className="answer-header"> | ||
<h5>{ans.created_by || "Anonymous"}</h5> | ||
<p>{timeStampFormatter(ans.created_on)}</p> | ||
</div> | ||
<p>{ans.answer}</p> | ||
<div className={"button-group"}> | ||
{ | ||
ans.isApproved ? | ||
<button | ||
name={`${ans?._id}`} | ||
onClick={(e) => handleDeleteAnswer(e.currentTarget.name)} | ||
className={"button-delete"} | ||
> | ||
Delete | ||
</button> | ||
: | ||
<> | ||
<button | ||
className={"button-delete"} | ||
id={`${ans?._id}`} | ||
onClick={(e) => handleDeleteAnswer(e.currentTarget.id)} | ||
> | ||
Reject | ||
</button> | ||
<button | ||
className={"button-approve"} | ||
id={`${ans?._id}`} | ||
onClick={(e) => updateAnswer(e.currentTarget.id, true)} | ||
> | ||
Approve | ||
</button> | ||
</> | ||
|
||
} | ||
</div> | ||
</div> | ||
) | ||
}) | ||
} | ||
</div> | ||
} | ||
</div> | ||
</Fade> | ||
</Modal> | ||
</div> | ||
) | ||
} |
104 changes: 104 additions & 0 deletions
104
frontend/src/pages/Admin/Components/Faq/Q&A/AnswersModel/AnswersModel.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
:root { | ||
font-family: "Futura LT Book"; | ||
} | ||
|
||
.modal-container { | ||
width: 70%; | ||
height: auto; | ||
background-color: white; | ||
outline: none !important; | ||
padding: 20px 20px; | ||
border-radius: 12px; | ||
|
||
h2 { | ||
margin: 0; | ||
} | ||
|
||
max-height: 100%; | ||
overflow-y: scroll; | ||
} | ||
|
||
.modal { | ||
display: flex; | ||
position: fixed; | ||
align-items: center; | ||
justify-content: center; | ||
align-items: center; | ||
overflow-y: scroll; | ||
outline: none !important; | ||
} | ||
|
||
.close-icon-container { | ||
display: flex; | ||
justify-content: end; | ||
} | ||
|
||
.close-icon { | ||
font-size: 24px; | ||
padding-right: 20px; | ||
cursor: pointer; | ||
color: #243e74; | ||
} | ||
|
||
.answer-container { | ||
width: 100%; | ||
border-bottom: 1px solid #ccc; | ||
padding-bottom: 20px; | ||
margin-top: 20px; | ||
|
||
p { | ||
margin-top: 8px; | ||
margin-bottom: 8px; | ||
font-size: 16px; | ||
} | ||
} | ||
|
||
.button-group { | ||
display: flex; | ||
width: 100%; | ||
align-items: center; | ||
gap: 10px; | ||
} | ||
|
||
.button-approve { | ||
padding: 10px; | ||
border: none; | ||
outline: none; | ||
border-radius: 5px; | ||
background-color: rgb(6, 158, 41); | ||
margin: 5px; | ||
color: #fff; | ||
width: 120px; | ||
font-size: 12px; | ||
font-weight: bold; | ||
transition: background-color 200ms; | ||
} | ||
|
||
.button-delete { | ||
padding: 10px; | ||
border: none; | ||
outline: none; | ||
border-radius: 5px; | ||
background-color: #fc0254; | ||
margin: 5px; | ||
color: #fff; | ||
width: 120px; | ||
font-size: 12px; | ||
font-weight: bold; | ||
transition: background-color 200ms; | ||
text-align: center; | ||
} | ||
|
||
.button-delete:hover { | ||
background-color: #fc3779; | ||
} | ||
|
||
@media screen and (max-width:768px) { | ||
.modal-container { | ||
width: 90%; | ||
} | ||
|
||
.close-icon { | ||
padding-right: 5px; | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
frontend/src/pages/Admin/Components/Faq/Q&A/AnswersModel/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './AnswersModel' |
Oops, something went wrong.