Fakultas Ilmu Komputer UI

Commit 45c9517e authored by Azhar Difa Arnanda's avatar Azhar Difa Arnanda 💬
Browse files

Merge branch 'dev' into 'staging'

Dev to Staging

See merge request !17
parents df4acada 21fb0184
Pipeline #70355 passed with stages
in 3 minutes and 28 seconds
......@@ -13,7 +13,8 @@ const ListBatch = () =>{
const shippingCosts = batches.results.map( (batch) => batch.shipping_cost);
if (shippingCosts.length){
const cost = shippingCosts.reduce( (acc, curr) => acc + curr);
totalCost = stringToCurrency(cost?.toString());
if (cost)
totalCost = stringToCurrency(cost.toString());
}else{
totalCost = stringToCurrency("0");
}
......
......@@ -11,6 +11,8 @@ import LanguageIcon from "@material-ui/icons/Language";
import useFetchSingleData from "../../utils/useFetchSingleData";
import LinkYellow from "../../component/LinkYellow";
import useDelete from "../../utils/useDelete";
import useSendData from "../../utils/useSendData";
import FormProgress from "./FormProgress";
import { stringToCurrency } from "../../component/TableUtils";
import {
Dialog,
......@@ -23,27 +25,48 @@ import {
const DetailProgram = ({ idProgram }) => {
const url = `${process.env.REACT_APP_BASE_URL}/programs/${idProgram}/`;
const progressUrl = url+"progress";
const progressUrl = url + "progress";
const [program, error] = useFetchSingleData(url);
const [progress, progressError] = useFetchSingleData(progressUrl);
const [deleteProgram, errorDelete] = useDelete(url);
const [openModal, setOpenModal] = useState(false);
const handleClose = () => setOpenModal(false);
const [dialogOpenImage, setDialogOpenImage] = useState(false);
const [dialogOpen, setDialogOpen] = useState(false);
const [image, setImage] = useState("");
const urlProgress = `${process.env.REACT_APP_BASE_URL}/programs/${idProgram}/progress`;
const [initialProgressData] = useFetchSingleData(urlProgress);
const [sendProgress] = useSendData({
url: urlProgress,
method: "POST",
redirect: "/program",
});
const onSubmitProgress = (data) => {
const formData = new FormData();
formData.append("date", data["tanggal_progress"]);
formData.append("description", data["berita_progress"]);
if (data["gambar_progress"].length !== 0)
formData.append("image", data["gambar_progress"][0]);
sendProgress(formData);
};
const handleClickOpen = (img) => {
setImage(img);
setDialogOpen(true);
if (img) {
setImage(img);
setDialogOpenImage(true);
} else {
setDialogOpen(true);
}
};
const handleClickClose = () => {
setDialogOpenImage(false);
setDialogOpen(false);
};
const start_date_time = new Date(program.start_date_time).toLocaleString();
const end_date_time = new Date(program.end_date_time).toLocaleString();
return (
<div
data-testid="page"
......@@ -367,65 +390,127 @@ const DetailProgram = ({ idProgram }) => {
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<div
css={css`
margin-top: 1rem;
margin-bottom: 1rem;
`}
>
<div
css={css`
margin-top: 1rem;
margin-bottom: 1rem;
`}
>
<div>
<div
css={css`
margin-top: 1rem;
`}
>
<div
css={css`
margin-top: 2rem;
margin-bottom: 1rem;
font-style: normal;
font-weight: normal;
font-size: 24px;
line-height: 22px;
margin-left: 70px;
`}
data-testid="progress"
>
Progress Program
{progressError && <ErrorDiv>Error, progress not found.</ErrorDiv>}
{progress.length > 0 ?
<div>
{progress.map ( p =>
<div key={p.id} css={css `margin-top: 1rem; font-size: 18px`}>
<p data-testid="progress-date">{p.date}</p>
<p>{p.description}</p>
{p.image !== null &&
<Button
onClick={() => handleClickOpen(p.image)}
variant="contained"
color="primary"
size="medium"
data-testid="button-see-proof"
<div
css={css`
margin-top: 2rem;
margin-bottom: 1rem;
font-style: normal;
font-weight: normal;
font-size: 24px;
line-height: 22px;
margin-left: 70px;
`}
data-testid="progress"
>
<Button
onClick={() => handleClickOpen()}
variant="contained"
size="medium"
data-testid="button-progress"
css={css`
display: block;
text-transform: none;
background: #ffffff;
border: 1px solid #3c8dbc;
box-sizing: border-box;
border-radius: 50px;
font-size: 14px;
line-height: 17px;
text-align: center;
letter-spacing: 0.2em;
color: #3c8dbc;
height: 2.3rem;
margin-bottom: 1em;
`}
>
Tambah Progress
</Button>
Progress Program
<Dialog
maxWidth="xl"
open={dialogOpen}
onClose={handleClickClose}
aria-labelledby="max-width-dialog-title"
data-testid="modal-progress"
>
<DialogTitle id="max-width-dialog-title">
Tambah Progress
</DialogTitle>
<DialogContent>
<FormProgress
{...{ onSubmitProgress, initialProgressData }}
/>
</DialogContent>
<DialogActions>
<Button
data-testid="close-button"
onClick={handleClickClose}
color="primary"
>
Close
</Button>
</DialogActions>
</Dialog>
{progressError && <ErrorDiv>Error, progress not found.</ErrorDiv>}
{progress.length > 0 ? (
<div>
{progress.map((p) => (
<div
key={p.id}
css={css`
margin-top: 1rem;
font-size: 18px;
`}
>
Gambar
</Button>
}
<p data-testid="progress-date">{p.date}</p>
<p>{p.description}</p>
{p.image !== null && (
<Button
onClick={() => handleClickOpen(p.image)}
variant="contained"
color="primary"
size="medium"
data-testid="button-see-proof"
>
Gambar
</Button>
)}
</div>
))}
</div>
) : (
<div
css={css`
margin-top: 1rem;
font-size: 18px;
`}
>
Belum ada progress
</div>
)}
</div>
:<div css={css `margin-top: 1rem ; font-size: 18px`}>Belum ada progress</div>
}
</div>
</div>
</div>
</div>
</div>
<Dialog
<Dialog
maxWidth="xl"
open={dialogOpen}
open={dialogOpenImage}
onClose={handleClickClose}
aria-labelledby="max-width-dialog-title"
>
......
import React, {useState} from "react";
import React from "react";
import useFetchSingleData from "../../utils/useFetchSingleData";
import { css } from "@emotion/core";
import { ErrorDiv, RowInput } from "../../component/html/html";
import { ErrorDiv } from "../../component/html/html";
import FormProgram from "./FormProgram";
import ArrowBackIcon from "@material-ui/icons/ArrowBack";
import ErrorOutlineIcon from "@material-ui/icons/ErrorOutline";
import { navigate } from "@reach/router";
import useSendData from "../../utils/useSendData";
import Button from "@material-ui/core/Button";
import Dialog from "@material-ui/core/Dialog";
import DialogActions from "@material-ui/core/DialogActions";
import DialogContent from "@material-ui/core/DialogContent";
import DialogTitle from "@material-ui/core/DialogTitle";
import FormProgress from "./FormProgress";
const EditProgram = ({ idProgram }) => {
const url = `${process.env.REACT_APP_BASE_URL}/programs/${idProgram}/`;
const [initialData, errorState] = useFetchSingleData(url);
const [send, error] = useSendData({ url, method: "PATCH", redirect: -1 });
const [dialogOpen, setDialogOpen] = useState(false);
const onSubmit = (data) => {
send(data);
};
const urlProgress = `${process.env.REACT_APP_BASE_URL}/programs/${idProgram}/progress`;
const [initialProgressData] = useFetchSingleData(urlProgress);
const [sendProgress] = useSendData({
url: urlProgress,
method: "POST",
redirect: "/program",
});
const onSubmitProgress = (data) => {
const formData = new FormData();
formData.append( "date", data["tanggal_progress"]);
formData.append("description", data["berita_progress"]);
if (data["gambar_progress"].length !== 0)
formData.append("image", data["gambar_progress"][0]);
sendProgress(formData);
};
if (errorState || Object.keys(initialData).length === 0)
return (
<div
......@@ -53,13 +30,7 @@ const EditProgram = ({ idProgram }) => {
Fetching data..
</div>
);
const handleClickOpen = () => {
setDialogOpen(true);
};
const handleClose = () => {
setDialogOpen(false);
};
return (
<div
data-testid="edit-program"
......@@ -115,51 +86,6 @@ const EditProgram = ({ idProgram }) => {
</div>
</div>
<FormProgram {...{ onSubmit, initialData }} />
<RowInput>
<Button
onClick={handleClickOpen}
variant="contained"
size="medium"
data-testid="button-progress"
css={css`
text-transform: none;
width: 100%;
background: #FFFFFF;
border: 1px solid #3c8dbc;
box-sizing: border-box;
border-radius: 50px;
font-size: 14px;
line-height: 17px;
text-align: center;
letter-spacing: 0.2em;
color: #3c8dbc;
height: 2.3rem;
`}
>
Tambah Progress
</Button>
</RowInput>
<Dialog
maxWidth="xl"
open={dialogOpen}
onClose={handleClose}
aria-labelledby="max-width-dialog-title"
data-testid="modal-progress"
>
<DialogTitle id="max-width-dialog-title">Tambah Progress</DialogTitle>
<DialogContent>
<FormProgress {...{ onSubmitProgress, initialProgressData }} />
</DialogContent>
<DialogActions>
<Button
data-testid="close-button"
onClick={handleClose}
color="primary"
>
Close
</Button>
</DialogActions>
</Dialog>
</div>
);
};
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment