Skip to content

Commit

Permalink
Merge pull request #12 from Restu-Averian/master
Browse files Browse the repository at this point in the history
Add suggestion_feature
  • Loading branch information
Andi-IM authored Sep 12, 2023
2 parents c68d6fb + 97a01bf commit 8d7e343
Show file tree
Hide file tree
Showing 8 changed files with 411 additions and 1 deletion.
7 changes: 7 additions & 0 deletions src/Routing.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import Login from "./page/Login";
import NotFound from "./page/NotFound";
import useCheckLogin from "./hooks/useCheckLogin";
import { Spin } from "antd";
import SuggestionLists from "./page/Suggestion/SuggestionLists";
import SuggestionDetail from "./page/Suggestion/SuggestionDetail";

const Routing = () => {
const { isLogin, isLoadingLogin } = useCheckLogin();
Expand All @@ -29,6 +31,11 @@ const Routing = () => {
path="/plant_lists/detail_plant/:id"
element={<EditPlants />}
/>
<Route path="/suggestion_lists" element={<SuggestionLists />} />
<Route
path="/suggestion_lists/detail_suggestion/:id"
element={<SuggestionDetail />}
/>
</>
) : (
<Route path="/login" element={<Login />} />
Expand Down
8 changes: 8 additions & 0 deletions src/components/Plants/ModalEditPhoto.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Button, Col, Form, Image, Input, Modal, Row } from "antd";
import { useEffect } from "react";
import { usePlantsFormContext } from "../../context/PlantsFormContext";

const ModalEditPhoto = () => {
Expand Down Expand Up @@ -27,6 +28,13 @@ const ModalEditPhoto = () => {
setOpenModalImg(false);
};

useEffect(() => {
FormEditPhotoInfo?.setFieldsValue({
description: objDetailImg?.description,
attribution: objDetailImg?.attribution,
});
}, [openModalImg]);

return (
<Modal
open={openModalImg}
Expand Down
4 changes: 4 additions & 0 deletions src/components/Sidebar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ const Sidebar = ({ children }) => {
key: "plant_lists",
label: "Plant Lists",
},
{
key: "suggestion_lists",
label: "Suggestion",
},
];

return (
Expand Down
23 changes: 23 additions & 0 deletions src/components/Suggestion/DataDetailSuggestion.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { Col, Row, Typography } from "antd";
import { Fragment } from "react";

const DataDetailSuggestion = ({ label, value, render }) => {
return (
<Fragment>
<Row gutter={[8, 8]} style={{ marginBottom: 20 }}>
<Col span={24}>
<Typography.Text>{label}</Typography.Text>
</Col>
<Col span={24}>
{typeof render !== "undefined" ? (
render()
) : (
<Typography.Text>{value}</Typography.Text>
)}
</Col>
</Row>
</Fragment>
);
};

export default DataDetailSuggestion;
25 changes: 25 additions & 0 deletions src/components/Suggestion/ModalDetailImgSuggestion.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { Col, Image, Modal, Row } from "antd";
import DataDetailSuggestion from "./DataDetailSuggestion";

const ModalDetailImgSuggestion = ({ open, setOpen, objDetailImg }) => {
return (
<Modal open={open} onCancel={() => setOpen(false)} title="Deskripsi Foto">
<Row gutter={16} align="middle">
<Col span={12}>
<Image />
</Col>
<Col span={12}>
<DataDetailSuggestion
label="Description"
value={objDetailImg?.description}
/>
<DataDetailSuggestion
label="Attribution"
value={objDetailImg?.attribution}
/>
</Col>
</Row>
</Modal>
);
};
export default ModalDetailImgSuggestion;
2 changes: 1 addition & 1 deletion src/page/Plants/PlantLists.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ const PlantLists = () => {
</Col>
</Row>

<Row>
<Row gutter={8}>
<Col span={24}>
<Spin spinning={loading}>
<Table dataSource={arrDatas} tableLayout="fixed">
Expand Down
226 changes: 226 additions & 0 deletions src/page/Suggestion/SuggestionDetail.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,226 @@
import {
ArrowLeftOutlined,
CloseCircleOutlined,
} from "@ant-design/icons/lib/icons";
import {
Badge,
Button,
Col,
Form,
Image,
Modal,
Row,
Space,
Spin,
Tooltip,
Typography,
} from "antd";
import { Fragment, useEffect, useState } from "react";
import { useNavigate, useParams } from "react-router-dom";
import DataDetailSuggestion from "../../components/Suggestion/DataDetailSuggestion";
import ModalDetailImgSuggestion from "../../components/Suggestion/ModalDetailImgSuggestion";
import getDocPS from "../../helpers/getDocPS";

const SuggestionDetail = ({ type }) => {
const [FormInstance] = Form.useForm();
const { id } = useParams();
const navigate = useNavigate();

const [imageData, setImageData] = useState([]);
const [openModalImg, setOpenModalImg] = useState(false);
const [objDetailImg, setObjDetailImg] = useState({
url: "",
desc: "",
attribution: "",
});
const [loading, setLoading] = useState(false);

const [objDetailSuggest, setObjDetailSuggest] = useState({});

const deleteImgHandler = (id) => {
Modal.confirm({
content: "Apakah yakin untuk hapus ?",
onOk: () => {
setImageData(imageData?.filter((data) => data?.id !== id));
},
okText: "Hapus",
okButtonProps: {
danger: true,
},
});
};

const getDetailSuggestions = () => {
setLoading(true);
getDocPS({
collectionName: "suggestions",
id,
})
?.then((objData) => {
setObjDetailSuggest(objData);
setImageData(objData?.images);
})
?.finally(() => {
setLoading(false);
});
};

useEffect(() => {
getDetailSuggestions();
}, []);

return (
<Spin spinning={loading}>
<div style={{ background: "white", padding: 20, borderRadius: 10 }}>
<Row align="middle">
<Col span={2}>
<Button
shape="circle"
icon={<ArrowLeftOutlined />}
onClick={() => {
navigate("/suggestion_lists");
}}
/>
</Col>

<Col span={22}>
<Typography.Title>Detail Suggestion</Typography.Title>
</Col>
</Row>

<Form
initialValues={{
...(type === "add" && {
common_name: [""],
}),
}}
form={FormInstance}
>
<Row gutter={[16, 16]}>
<Col span={12}>
<DataDetailSuggestion
label="Plant Name"
value={objDetailSuggest?.name || "-"}
/>
<DataDetailSuggestion
label="Species"
value={objDetailSuggest?.species || "-"}
/>
<DataDetailSuggestion
label="Other Name"
render={() => {
if (objDetailSuggest?.common_name?.length) {
return (
<ul>
{objDetailSuggest?.common_name?.map((cmnName, key) => (
<li key={key}>{cmnName?.name}</li>
))}
</ul>
);
}
return <Typography.Text>No Other Name</Typography.Text>;
}}
/>
<DataDetailSuggestion
label="Description"
value={objDetailSuggest?.description}
/>
</Col>
<Col span={12}>
<DataDetailSuggestion
label="Genus"
value={objDetailSuggest?.taxonomy?.genus || "-"}
/>
<DataDetailSuggestion
label="Class"
value={objDetailSuggest?.taxonomy?.class || "-"}
/>
<DataDetailSuggestion
label="Family"
value={objDetailSuggest?.taxonomy?.family || "-"}
/>
<DataDetailSuggestion
label="Order"
value={objDetailSuggest?.taxonomy?.order || "-"}
/>
<DataDetailSuggestion
label="Phylum"
value={objDetailSuggest?.taxonomy?.phylum || "-"}
/>
</Col>
</Row>

<Row>
<Col span={24}>
<Space size="large" wrap>
<DataDetailSuggestion
label="Images"
render={() => {
if (imageData?.length) {
return (
<>
{imageData?.map((dataPreview, idx) => (
<Tooltip
title={dataPreview?.desc || "Tidak ada informasi"}
key={idx}
>
<Badge
count={
<Button
icon={
<CloseCircleOutlined
style={{
cursor: "pointer",
fontSize: 28,
}}
/>
}
shape="circle"
danger
onClick={() =>
deleteImgHandler(dataPreview?.id)
}
style={{
background: "transparent",
border: 0,
}}
/>
}
>
<Image
style={{ cursor: "pointer" }}
src={dataPreview?.url}
width={100}
height={100}
preview={false}
onClick={() => {
setObjDetailImg({
...dataPreview,
});
setOpenModalImg(true);
}}
/>
</Badge>
</Tooltip>
))}
</>
);
}
return <Typography.Text>No Images</Typography.Text>;
}}
/>
</Space>
</Col>
</Row>
</Form>
</div>

<ModalDetailImgSuggestion
open={openModalImg}
setOpen={setOpenModalImg}
objDetailImg={objDetailImg}
/>
</Spin>
);
};
export default SuggestionDetail;
Loading

0 comments on commit 8d7e343

Please sign in to comment.