Skip to content

Commit

Permalink
Merge pull request #26 from NwinNwin/steven-feedback+modal
Browse files Browse the repository at this point in the history
Steven feedback+modal
  • Loading branch information
stevem-zhou authored Sep 20, 2023
2 parents 3fa132e + b229eca commit 07094ed
Show file tree
Hide file tree
Showing 8 changed files with 287 additions and 139 deletions.
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"react-resizable-panels": "^0.0.53",
"react-router-dom": "^6.11.2",
"react-scripts": "5.0.1",
"swiper": "^10.0.4",
"swiper": "^10.2.0",
"web-vitals": "^2.1.4"
},
"scripts": {
Expand Down
134 changes: 134 additions & 0 deletions src/components/FeedbackModal/FeedbackModal.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
import {
Text,
Flex,
Modal,
ModalOverlay,
ModalContent,
ModalCloseButton,
ModalHeader,
ModalFooter,
Button,
} from "@chakra-ui/react";
import axios from "axios";
import DataContext from "../../context/DataContext";
import { useState, useContext } from "react";

export default function FeedbackModal({
setData,
infoOnClose,
isOpen,
onClose,
props,
}) {
const [feedbackHelped, setFeedbackHelped] = useState(null);
const { setLoading } = useContext(DataContext);

async function handleFeedback() {
setLoading(false);
axios
.put(`${process.env.REACT_APP_AWS_BACKEND_URL}/items/${props.id}`, {
isHelped: feedbackHelped,
})
.then(() => console.log("Success"))
.catch((err) => console.log(err));

setData((prevItems) => {
if (prevItems && prevItems.length > 0) {
return prevItems.map((item) => {
if (item.id === props.id) {
item.isresolved = true;
item.isHelped = feedbackHelped;
}
return item;
});
}
return prevItems;
});
setLoading(true);
}

return (
<Modal
isOpen={isOpen}
onClose={() => {
if (feedbackHelped === null) {
onClose();
} else {
onClose();
infoOnClose();
}
}}
>
<ModalOverlay />
{feedbackHelped === null ? (
<ModalContent>
<ModalHeader
display={"flex"}
alignItems={"center"}
justifyContent={"center"}
>
⚠️ Feedback ⚠️
</ModalHeader>
<ModalCloseButton />
<Flex justifyContent={"center"} alignItems={"center"}>
<Text>Did ZotnFound help with resolving your item?</Text>
</Flex>
<ModalFooter
display={"flex"}
alignItems={"center"}
justifyContent={"center"}
>
<Button
colorScheme="red"
mr={3}
onClick={() => {
setFeedbackHelped(false);
}}
>
No 👎
</Button>
<Button
colorScheme="green"
onClick={() => {
setFeedbackHelped(true);
}}
>
Yes 👍
</Button>
</ModalFooter>
</ModalContent>
) : (
<ModalContent>
<ModalHeader
display={"flex"}
alignItems={"center"}
justifyContent={"center"}
>
❤️ Thank You For Your Feedback ❤️
</ModalHeader>
<ModalCloseButton />
<Flex justifyContent={"center"} alignItems={"center"}>
<Text>Your feedback has been recorded.</Text>
</Flex>
<ModalFooter
display={"flex"}
alignItems={"center"}
justifyContent={"center"}
>
<Button
colorScheme="red"
mr={3}
onClick={() => {
handleFeedback();
onClose();
infoOnClose();
}}
>
Close
</Button>
</ModalFooter>
</ModalContent>
)}
</Modal>
);
}
2 changes: 2 additions & 0 deletions src/components/Home/Home.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ export default function Home() {
const [screenWidth, setScreenWidth] = useState(window.screen.width);
const [uploadImg, setUploadImg] = useState("");

console.log(data)

// LOGIN MODAL
const {
isOpen: isLoginModalOpen,
Expand Down
2 changes: 1 addition & 1 deletion src/components/ImageContainer/ImageContainer.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export default function ImageContainer({ image, isresolved }) {
alignItems={"center"}
marginTop={30}
flexDir={"column"}
w={400}
w={450}
>
<Text fontSize={18} as="b" color={"white"}>
RETURNED
Expand Down
Loading

0 comments on commit 07094ed

Please sign in to comment.