Fakultas Ilmu Komputer UI

DetailDonasi.jsx 7.41 KB
Newer Older
Jeffrey's avatar
Jeffrey committed
1
2
3
import React, { useState } from "react";
import useFetchSingleData from "../../utils/useFetchSingleData";
import { css } from "@emotion/core";
Michael Wiryadinata Halim's avatar
Michael Wiryadinata Halim committed
4
5
6
import ArrowBackIcon from "@material-ui/icons/ArrowBack";
import PhoneIcon from "@material-ui/icons/Phone";
import PhotoIcon from "@material-ui/icons/Photo";
Jeffrey's avatar
Jeffrey committed
7
8
9
10
11
12
13
14
15
16
import { Link, navigate } from "@reach/router";
import PersonIcon from "@material-ui/icons/Person";
import { stringToDate } from "../../component/TableUtils";
import { ErrorDiv } from "../../component/html/html";
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 FormDonasi from "./FormDonasi";
17
import StatusDonasi from "../../component/StatusDonasi";
Jeffrey's avatar
Jeffrey committed
18
const DetailDonasi = ({ idDonasi }) => {
19
  const url = `${process.env.REACT_APP_BASE_URL}/program-donations/${idDonasi}/`;
Jeffrey's avatar
Jeffrey committed
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
  const [donation, error] = useFetchSingleData(url);
  const [dialogOpen, setDialogOpen] = useState(false);

  const handleClickOpen = () => {
    setDialogOpen(true);
  };

  const handleClose = () => {
    setDialogOpen(false);
  };

  if (Object.keys(donation).length === 0)
    return (
      <div
        data-testid="waiting-detail-donasi"
        css={css`
          display: flex;
          margin: 2rem 3rem 3rem 3rem;
          flex-direction: column;
          font-size: 25px;
        `}
      >
        {error && <ErrorDiv>Something error</ErrorDiv>}
        Fetching data..
      </div>
    );
  return (
    <div
      data-testid="page-detail-donasi"
      css={css`
        display: flex;
        margin: 2rem 3rem 3rem 3rem;
        flex-direction: column;
        justify-content: space-around;
54
        height: 75vh;
Jeffrey's avatar
Jeffrey committed
55
56
57
      `}
    >
      {error && <ErrorDiv>Something error</ErrorDiv>}
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
      <div>
        <button
          css={css`
            align-self: start;
            background-color: Transparent;
            background-repeat: no-repeat;
            border: none;
            cursor: pointer;
            overflow: hidden;
            outline: none;
            display: inline-block;
            vertical-align: middle;
          `}
          onClick={() => navigate(-1)}
        >
          <ArrowBackIcon fontSize="large" />
        </button>
        <div
          css={css`
            display: inline-block;
            font-size: 2rem;
            vertical-align: middle;
          `}
        >
          DETAIL DONASI
        </div>
Jeffrey's avatar
Jeffrey committed
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
      </div>
      <div
        css={css`
          font-size: 1.5rem;
          display: flex;
          align-content: space-between;
        `}
      >
        <div
          css={css`
            display: flex;
          `}
        >
          <div
            css={css`
              margin-right: 1rem;
            `}
          >
            Donation code:
          </div>
          <div>{donation.donation_number}</div>
        </div>
106
107
108
109
110
111
112
113
114
        {donation.donation_status !== "002" &&
          donation.donation_status !== "003" && (
            <FormDonasi
              {...{
                idDonasi,
                defaultStatus: donation.donation_status,
              }}
            />
          )}
Jeffrey's avatar
Jeffrey committed
115
116
117
118
119
120
121
122
123
124
125
126
127
128
      </div>
      <div
        css={css`
          font-size: 1.5rem;
          display: flex;
        `}
      >
        <div
          css={css`
            margin-right: 1rem;
          `}
        >
          Status:{" "}
        </div>
129
        <StatusDonasi
Jeffrey's avatar
Jeffrey committed
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
          label={donation.readable_donation_status}
          status={donation.donation_status}
        />
      </div>
      <div
        css={css`
          font-size: 1.2rem;
          display: flex;
        `}
      >
        <div
          css={css`
            margin-right: 0.5rem;
          `}
        >
          Date created:{" "}
        </div>
        <div>{stringToDate(donation.created_at)}</div>
      </div>
      <div
        css={css`
          font-size: 1.2rem;
          display: flex;
        `}
      >
        <div
          css={css`
            margin-right: 0.5rem;
          `}
        >
          Date updated:{" "}
        </div>
        <div>{stringToDate(donation.updated_at)}</div>
      </div>
      <div
        css={css`
          display: flex;
          font-size: 1.2rem;
          align-items: baseline;
        `}
      >
171
        <PersonIcon style={{ color: "FFC80A" }} />
Jeffrey's avatar
Jeffrey committed
172
173
174
175
176
177
178
179
180
181
182
        <Link to={`/pengguna/${donation.user}`}>
          {donation.user_full_name} / {donation.user_username}
        </Link>
      </div>
      <div
        css={css`
          display: flex;
          font-size: 1.2rem;
          align-items: baseline;
        `}
      >
183
        <PhoneIcon style={{ color: "FFC80A" }} />
Jeffrey's avatar
Jeffrey committed
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
        <div>{donation.user_phone_number}</div>
      </div>
      <div
        css={css`
          display: flex;
          flex-direction: column;
        `}
      >
        {" "}
        <div
          css={css`
            font-size: 1.3rem;
          `}
        >
          <div>
            {donation.proof_of_bank_transfer === null ? (
              <div>User belum mengirimkan bukti transfer</div>
            ) : (
              <div
                css={css`
                  display: flex;
                  flex-direction: column;
                `}
              >
                <div
                  css={css`
                    display: flex;
                    font-size: 1.2rem;
                    align-items: baseline;
                  `}
                >
                  <div
                    css={css`
                      margin-right: 1rem;
                    `}
                  >
                    Sender name:{" "}
                  </div>
                  <div>{donation.user_bank_account_name}</div>
                </div>
                <div
                  css={css`
                    display: flex;
                    font-size: 1.2rem;
                    align-items: baseline;
                  `}
                >
                  <div
                    css={css`
                      margin-right: 1rem;
                    `}
                  >
                    Sender account number:{" "}
                  </div>
                  <div>{donation.user_bank_account_number}</div>
                </div>
                <Button
                  onClick={handleClickOpen}
                  variant="contained"
                  color="primary"
                  size="medium"
Michael Wiryadinata Halim's avatar
Michael Wiryadinata Halim committed
245
                  startIcon={<PhotoIcon />}
Jeffrey's avatar
Jeffrey committed
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
                  data-testid="button-see-proof"
                >
                  Bukti
                </Button>
              </div>
            )}
          </div>
        </div>
      </div>
      <Dialog
        maxWidth="xl"
        open={dialogOpen}
        onClose={handleClose}
        aria-labelledby="max-width-dialog-title"
      >
        <DialogTitle id="max-width-dialog-title">Bukti Transfer</DialogTitle>
        <DialogContent>
          <img
            css={css`
              height: 80vh;
              width: 80vw;
              object-fit: contain;
            `}
            src={donation.proof_of_bank_transfer}
            alt="Bukti Pembayaran"
          />
        </DialogContent>
        <DialogActions>
          <Button
            data-testid="button-close-proof"
            onClick={handleClose}
            color="primary"
          >
            Close
          </Button>
        </DialogActions>
      </Dialog>
    </div>
  );
};

export default DetailDonasi;