generated from HackYourFuture-CPH/boilerplate-for-fp
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #26 from HackYourFuture-CPH/frontend-question/meraj
Frontend question/meraj
- Loading branch information
Showing
10 changed files
with
622 additions
and
251 deletions.
There are no files selected for viewing
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
85 changes: 85 additions & 0 deletions
85
packages/client/src/components/CheckinQuestionsPage/AddCheckinQuestionModal.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,85 @@ | ||
import React, { useState } from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { Button, TextField, Modal, Box, Typography } from '@mui/material'; | ||
|
||
const style = { | ||
position: 'absolute', | ||
top: '50%', | ||
left: '50%', | ||
transform: 'translate(-50%, -50%)', | ||
width: 400, | ||
bgcolor: 'background.paper', | ||
boxShadow: 24, | ||
p: 4, | ||
}; | ||
|
||
const AddCheckinQuestionModal = ({ | ||
showAddModal, | ||
setShowAddModal, | ||
newQuestionText, | ||
setNewQuestionText, | ||
handleAdd, | ||
}) => { | ||
const [error, setError] = useState(false); | ||
|
||
const onSave = () => { | ||
if (newQuestionText.trim() === '') { | ||
setError(true); | ||
return; | ||
} | ||
handleAdd(); | ||
setNewQuestionText(''); | ||
}; | ||
|
||
return ( | ||
<Modal | ||
open={showAddModal} | ||
onClose={() => setShowAddModal(false)} | ||
aria-labelledby="modal-modal-title" | ||
aria-describedby="modal-modal-description" | ||
> | ||
<Box sx={style} className="modal-container"> | ||
<Typography | ||
variant="h6" | ||
style={{ textAlign: 'center', marginBottom: '10px' }} | ||
> | ||
Add Checkin Question | ||
</Typography> | ||
<TextField | ||
id="outlined-multiline-static" | ||
label="Write your question here..." | ||
multiline | ||
rows={4} | ||
value={newQuestionText} | ||
onChange={(e) => { | ||
setNewQuestionText(e.target.value); | ||
setError(false); | ||
}} | ||
fullWidth | ||
variant="outlined" | ||
error={error} | ||
helperText={error ? 'Question cannot be empty' : ''} | ||
sx={{ mb: 2 }} | ||
/> | ||
<Box sx={{ display: 'flex', flexDirection: 'column', gap: '10px' }}> | ||
<Button variant="contained" onClick={onSave}> | ||
Add Question | ||
</Button> | ||
<Button variant="outlined" onClick={() => setShowAddModal(false)}> | ||
Cancel | ||
</Button> | ||
</Box> | ||
</Box> | ||
</Modal> | ||
); | ||
}; | ||
|
||
AddCheckinQuestionModal.propTypes = { | ||
showAddModal: PropTypes.bool.isRequired, | ||
setShowAddModal: PropTypes.func.isRequired, | ||
newQuestionText: PropTypes.string.isRequired, | ||
setNewQuestionText: PropTypes.func.isRequired, | ||
handleAdd: PropTypes.func.isRequired, | ||
}; | ||
|
||
export { AddCheckinQuestionModal }; |
64 changes: 64 additions & 0 deletions
64
packages/client/src/components/CheckinQuestionsPage/EditCheckinQuestionModal.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,64 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { Button, TextField, Modal, Box, Typography } from '@mui/material'; | ||
|
||
const EditCheckinQuestionModal = ({ | ||
showEditModal, | ||
questionId, | ||
questionText, | ||
setQuestionText, | ||
handleSaveEdit, | ||
handleClose, | ||
}) => { | ||
if (!showEditModal) { | ||
return null; | ||
} | ||
|
||
return ( | ||
<Modal | ||
open={showEditModal} | ||
onClose={handleClose} | ||
aria-labelledby="modal-modal-title" | ||
aria-describedby="modal-modal-description" | ||
> | ||
<Box className="modal-container"> | ||
<Typography variant="h6" className="modal-title"> | ||
Edit Checkin Question | ||
</Typography> | ||
<TextField | ||
className="modal-textfield" | ||
id="outlined-multiline-static" | ||
label="Write your question here..." | ||
multiline | ||
rows={4} | ||
value={questionText} | ||
onChange={(e) => setQuestionText(e.target.value)} | ||
fullWidth | ||
variant="outlined" | ||
/> | ||
<Box className="button-container-edit-question"> | ||
<Button | ||
variant="contained" | ||
onClick={() => handleSaveEdit(questionId)} | ||
> | ||
Save | ||
</Button> | ||
<Button variant="outlined" onClick={handleClose}> | ||
Cancel | ||
</Button> | ||
</Box> | ||
</Box> | ||
</Modal> | ||
); | ||
}; | ||
|
||
EditCheckinQuestionModal.propTypes = { | ||
showEditModal: PropTypes.bool.isRequired, | ||
questionId: PropTypes.number.isRequired, | ||
questionText: PropTypes.string.isRequired, | ||
setQuestionText: PropTypes.func.isRequired, | ||
handleSaveEdit: PropTypes.func.isRequired, | ||
handleClose: PropTypes.func.isRequired, | ||
}; | ||
|
||
export { EditCheckinQuestionModal }; |
53 changes: 53 additions & 0 deletions
53
packages/client/src/components/CheckinQuestionsPage/QuestionList.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,53 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { Typography, IconButton } from '@mui/material'; | ||
import EditIcon from '@mui/icons-material/Edit'; | ||
import DeleteIcon from '@mui/icons-material/Delete'; | ||
import '../../containers/QuestionPage/CheckinQuestions.css'; | ||
|
||
const QuestionList = ({ | ||
checkinQuestions, | ||
editQuestionId, | ||
handleEditQuestion, | ||
handleDeleteQuestion, | ||
}) => { | ||
return ( | ||
<ul className="question-list"> | ||
{checkinQuestions.map((question) => ( | ||
<li key={question.question_id} className="question-item"> | ||
<div className="question-content"> | ||
<Typography>{question.question_text}</Typography> | ||
{editQuestionId !== question.question_id && ( | ||
<div className="question-actions"> | ||
<IconButton | ||
onClick={() => | ||
handleEditQuestion( | ||
question.question_id, | ||
question.question_text, | ||
) | ||
} | ||
> | ||
<EditIcon /> | ||
</IconButton> | ||
<IconButton | ||
onClick={() => handleDeleteQuestion(question.question_id)} | ||
> | ||
<DeleteIcon /> | ||
</IconButton> | ||
</div> | ||
)} | ||
</div> | ||
</li> | ||
))} | ||
</ul> | ||
); | ||
}; | ||
|
||
QuestionList.propTypes = { | ||
checkinQuestions: PropTypes.arrayOf(PropTypes.object).isRequired, | ||
editQuestionId: PropTypes.number, | ||
handleEditQuestion: PropTypes.func.isRequired, | ||
handleDeleteQuestion: PropTypes.func.isRequired, | ||
}; | ||
|
||
export default QuestionList; |
42 changes: 0 additions & 42 deletions
42
packages/client/src/containers/LandingPage/CheckinQuestionsPage/AddCheckinQuestionModal.jsx
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.