From 55cc9324be83597f5547ce903f6488d002eb9f6c Mon Sep 17 00:00:00 2001 From: Fadli Date: Fri, 6 Jan 2023 11:30:30 +0700 Subject: [PATCH] - revert topup button --- src/pages/Membership/DetailUser.js | 1492 +++++++--------------------- 1 file changed, 377 insertions(+), 1115 deletions(-) diff --git a/src/pages/Membership/DetailUser.js b/src/pages/Membership/DetailUser.js index 35a5b06..a0fb07b 100644 --- a/src/pages/Membership/DetailUser.js +++ b/src/pages/Membership/DetailUser.js @@ -1,1164 +1,426 @@ -import React, { useContext, useEffect, useState } from "react"; +import React, { useContext, useState } from "react"; import { Button, - Card, - Col, + Divider, + Form, + Input, + List, message, - Row, + Modal, Space, Table, - Typography, - Tabs, - List, Tag, - Divider, - Image, - Modal, - Form, - DatePicker, } from "antd"; -import { UserOutlined, FilterOutlined,ExportOutlined } from "@ant-design/icons"; -import { BreadcumbComponent } from "../../component/BreadcumbComponent"; -import { LINKS } from "../../routes/app"; -import { useStore } from "../../utils/useStore"; import { observer } from "mobx-react-lite"; -import { format, parseISO } from "date-fns"; -import { ModalLoaderContext } from "../../utils/modal"; -import { useParams } from "react-router-dom"; -import { appConfig } from "../../config/app"; -import { MembershipModal } from "./MembershipModal"; -import moment from "moment"; -import FileSaver from "file-saver"; +import { ExclamationCircleOutlined } from "@ant-design/icons"; +import { useHistory } from "react-router-dom"; +import { useStore } from "../utils/useStore"; +import { LINKS } from "../routes/app"; +import { TopupsaldoModal } from "./TopupsaldoModal"; +import { ModalLoaderContext } from "../utils/modal"; -const { Title, Text } = Typography; -const { TabPane } = Tabs; -export const DetailUser = observer(() => { +export const SupplierComponent = observer((props) => { const store = useStore(); const [form] = Form.useForm(); - const [formExport] = Form.useForm(); + const history = useHistory(); + const [idData, setIdData] = useState(""); const modalLoader = useContext(ModalLoaderContext); - const { id } = useParams(); - const [visibleModal, setVisibleModal] = useState(false); - const [initialData, setInitialData] = useState({}); - const [confirmLoading, setConfirmLoading] = useState(false); - const [filterStart, setFilterStart] = useState([]); - const [filterEnd, setFilterEnd] = useState([]); - const [visibleHis, setVisibleHis] = useState(true); - const [actionFilter, setAction] = useState(false); - const [modalExport, setModalExport] = useState(false); - useEffect(() => { - (async () => { - modalLoader.setLoading(true); - await getData(); - modalLoader.setLoading(false); - })(); - - return () => { - store.membership.dataDetail = {}; - store.transaction.dataHistoryTopUp = []; - store.authentication.dataProfit = []; - store.transaction.dataDetailHistoryTransaction = []; - }; - }, []); - - const getData = async () => { - const isAdmin = store.authentication.userData.role === "Admin"; - await Promise.allSettled([ - store.transaction.getDataHistoryTopUp(id), - store.authentication.getProfit(id), - store.authentication.getProfile(), - store.transaction.getDetailHistoryTransaction(id), - store.membership.getDetail(id), - store.role.getData(isAdmin), - ]); + const handleEditButton = (data) => { + console.log(data, "isi data"); + form.setFieldsValue({ + name: data.name, + code: data.code, + status: data.status, + }); + store.supplier.visibleModalSupplier = true; + setIdData(data.id); }; - const changeStatus = async (id, is_active) => { - let status = is_active ? "inactive" : "active"; - let status2 = is_active ? "Inactivating" : "Activating"; - console.log(status, "status terbaru"); + const handleTopup = (data) => { + console.log(data, "isi data"); + form.setFieldsValue({ + code: data.code, + }); + store.supplier.visibleModalTransaction = true; + store.supplier.code = data.code; + }; + + const changeStatus = async (id, isActive) => { + const status = isActive ? "inactive" : "active"; + const status2 = isActive ? "Inactivating" : "Activating"; try { modalLoader.setLoading(true); - const response = await store.membership.changeStatus(id, status); + const response = await store.supplier.changeStatus(id, status); modalLoader.setLoading(false); - response?.body?.statusCode === 201 || response?.body?.statusCode === 200 - ? message.success(`Success ${status2} Membership`) - : message.error(`Failed ${status2} Membership`); - await getData(); + response?.body?.statusCode === 201 + ? message.success(`Success ${status2} Supplier`) + : message.error(`Failed ${status2} Supplier`); } catch (err) { modalLoader.setLoading(false); - message.error(`Failed ${status2} Membership`); - } - }; - - const withdrawProfit = async (id) => { - try { - modalLoader.setLoading(true); - const response = await store.membership.withdrawProfit(id); - modalLoader.setLoading(false); - - response?.body?.statusCode === 201 || response?.body?.statusCode === 200 - ? message.success(`Success Withdraw Profit`) - : message.error(`Failed Withdraw Profit`); - await getData(); - } catch (err) { - modalLoader.setLoading(false); - message.error(`Failed Withdraw Profit`); - } - }; - - const onSubmit = async (data) => { - data.superior = true; - setConfirmLoading(true); - modalLoader.setLoading(true); - try { - let response; - if (initialData.isChangePassword) { - response = await store.membership.changePassword(initialData.id, data); - } else { - response = await store.membership.update(initialData.id, data); - } - - setVisibleModal(false); - - if (response?.body?.statusCode === 200) { - message.success( - initialData.isChangePassword - ? "Success Change Member Password" - : "Success Update Data Member" - ); - } else { - message.error( - initialData.isChangePassword - ? "Failed Change Member Password" - : "Failed Update Data Member" - ); - } - await getData(); - } catch (e) { - modalLoader.setLoading(false); - message.error( - initialData.isChangePassword - ? "Failed Update Member Password" - : "Failed Update Data Member" - ); - } - modalLoader.setLoading(false); - setConfirmLoading(false); - }; - - const handleResend = async (id) => { - modalLoader.setLoading(true); - try { - const response = await store.approval.resendUser(id); - console.log(response); - response.body.statusCode !== 201 && response.body.statusCode !== 200 - ? message.error(response?.body?.message || `Failed Approve`) - : message.success(response?.body?.message || `Success Approve`); - await getData(); - } catch (e) { - console.error(e, "apa errornya"); - message.error(e.response?.body?.message || "Fail Approve"); - } - modalLoader.setLoading(false); - }; - - const handleSubmitExport = async () => { - const date = formExport.getFieldsValue(); - const dataDate ={ - dateStart: moment(date.tanggal_export).format("YYYY-MM-DD") - } - modalLoader.setLoading(true); - try { - await store.transaction.exportTransaction(store.membership.dataDetail, dataDate) - // console.log('responseiniyak', response); - // message.success("Success export"); - setModalExport(false); - modalLoader.setLoading(false); - } catch (e) { - setModalExport(false); - console.error(e, "apa errornya"); - message.error(e.response?.body?.message || "Failed to export"); - modalLoader.setLoading(false); + console.log("error", err); + message.error(`Failed ${status2} Supplier`); } }; const columns = [ { - title: "Pengirim", - dataIndex: "sender_name", - key: "sender_name", - }, - { - title: "Nominal", - dataIndex: "amount", - key: "amount", - render: (text) => - new Intl.NumberFormat("id-ID", { - style: "currency", - currency: "IDR", - }).format(text), - }, - { - title: "Tanggal Transaksi", - dataIndex: "transaction_date", - key: "transaction_date", - render: (text, record) => { - return ( - - {format(parseISO(record.transaction_date), "dd MMMM yyyy")} - - ); - }, - }, - ]; - - const column = [ - { - title: "Nama Produk", + title: "Nama", dataIndex: "name", key: "name", }, { - title: "Supplier", - dataIndex: "supplier_name", - key: "supplier_name", + title: "Kode", + dataIndex: "code", + key: "code", + width: "5%", }, { - title: "Profit Produk", - dataIndex: "mark_up_price", - key: "mark_up_price", + title: "Saldo di Supplier", + dataIndex: ["coa", "amount"], + key: ["coa", "amount"], + width: "20%", + render: (text, record) => + new Intl.NumberFormat("id-ID", { + style: "currency", + currency: "IDR", + }).format(text), }, { - title: "Harga", - dataIndex: "price", - key: "price", - render: (text) => - new Intl.NumberFormat("id-ID", { - style: "currency", - currency: "IDR", - }).format(text), - }, - { - title: "Sisa Saldo", - dataIndex: "balance_remaining", - key: "balance_remaining", - render: (text) => - new Intl.NumberFormat("id-ID", { - style: "currency", - currency: "IDR", - }).format(text), - }, - { - title: "Pembeli", - dataIndex: "buyer", - key: "buyer", - }, - { - title: "Tujuan", - dataIndex: "transaction_destination", - key: "transaction_destination", - }, - { - title: "Kode Transaksi", - dataIndex: "transaction_code", - key: "transaction_code", + title: "Saldo di System", + dataIndex: ["coa_undistribute", "amount"], + key: ["coa_undistribute", "amount"], + width: "20%", + render: (text, record) => + new Intl.NumberFormat("id-ID", { + style: "currency", + currency: "IDR", + }).format(text), }, { title: "Status", dataIndex: "status", key: "status", - render: (text, record) => { - return ( + width: "5%", + render: (text, record) => ( - {record.status === 1 - ? "Success" - : record.status === 0 - ? "Pending" - : "Failed"} + {record?.status === true ? " ACTIVE" : "INACTIVE"} - ); - }, + ), }, { - title: "No Seri", - dataIndex: "seri_number", - key: "seri_number", - }, - { - title: "IDTrx Mitra", - dataIndex: "partner_transaction_code", - key: "partner_transaction_code", - }, - { - title: "Tanggal Transaksi", - dataIndex: "created_at", - key: "created_at", - width: "15%", - render: (text, record) => { - return ( - - {format(parseISO(record.created_at), "MM-dd-yyyy HH:mm:ss")} - - ); - }, - }, - { - title: "Alasan Gagal", - dataIndex: "failed_reason", - key: "failed_reason", - }, - ]; - if (store.authentication.userData.role !== "Admin") delete column[1]; - if (store.authentication.userData.role !== "Admin") delete column[2]; - if (store.authentication.userData.role !== "Admin") delete column[4]; - - const routeData = [ - { - route: LINKS.HOME, - name: "Beranda", - }, - { - route: LINKS.MEMBERSHIP, - name: Keanggotaan, - }, - { - route: LINKS.USER_DETAIL.replace(":id", id), - name: Detail User, - }, - ]; - - const dataRoute = [ - { - route: LINKS.MEMBERSHIP, - name: "Keanggotaan", - }, - { - route: LINKS.USER_DETAIL.replace(":id", id), - name: Detail User, - }, - ]; - - const styleSaldoTitle = store.ui.mediaQuery.isDesktop - ? { - display: "flex", - justifyContent: "center", - } - : { fontSize: "0.75rem" }; - const styleSaldoContent = store.ui.mediaQuery.isDesktop - ? { - fontSize: "1.25rem", - display: "flex", - justifyContent: "center", - } - : null; - const data = store.authentication.listImage; - console.log(data, "ini data"); - console.log( - store.authentication.dataProfit.userDetail?.image_identity, - "detail" - ); - - const handleRemoveFilter = async () => { - store.transaction.filterStart = null; - store.transaction.filterEnd = null; - form.resetFields(); - setFilterStart([]); - setFilterEnd([]); - actionFilter === true - ? await store.transaction.getDataHistoryTopUp(id) - : await store.transaction.getDetailHistoryTransaction( - store.authentication.dataProfit.id - ); - // await store.transaction.getDetailHistoryTransaction( - // store.authentication.dataProfit.id - // ); - store.transaction.visibleModalFilterTransaction = false; - setAction(false); - }; - - const handleCancelFilter = async () => { - store.transaction.filterStart = null; - store.transaction.filterEnd = null; - store.transaction.visibleModalFilterTransaction = false; - actionFilter === true - ? await store.transaction.getDataHistoryTopUp(id) - : await store.transaction.getDetailHistoryTransaction( - store.authentication.dataProfit.id - ); - // await store.transaction.getDetailHistoryTransaction( - // store.authentication.dataProfit.id - // ); - setAction(false); - }; - - const handleSubmitFilter = async () => { - const data = form.getFieldsValue(); - store.transaction.filterStart = moment(data.start_date).format( - "YYYY-MM-DD" - ) + " 00:00:00"; - store.transaction.filterEnd = moment(data.end_date).format( - "YYYY-MM-DD" - ) + " 23:59:59"; - modalLoader.setLoading(true); - actionFilter === true - ? await store.transaction.getDataHistoryTopUp(id) - : await store.transaction.getDetailHistoryTransaction( - store.authentication.dataProfit.id - ); - modalLoader.setLoading(false); - store.transaction.filterStart = null; - store.transaction.filterEnd = null; - store.transaction.visibleModalFilterTransaction = false; - setAction(false); - }; - const footerLayoutFilter = [ - , - , - , - ]; - return ( -
- - - - - Detail User - - - ( + + - - - - )} - {((store.authentication.userData.role === "Sales" && - store.membership.dataDetail.is_rejected === true && - store.membership.dataDetail.is_active === false) || - (store.authentication.userData.role === "Supervisor" && - store.membership.dataDetail.is_rejected === true && - store.membership.dataDetail.is_active === false)) && ( - - )} - {store.authentication.userData.role === "Admin" && ( - <> - - - - )} - - - - - - - - Name - - - {store.authentication.dataProfit.userDetail?.name} - - - Username - - - {store.authentication.dataProfit.username} - - {/* - Role - - - {store.authentication.dataProfit.roles?.name} - */} - - Phone Number - - - - {store.authentication.dataProfit.userDetail?.phone_number} - - - - Id Number - - - - {store.authentication.dataProfit.userDetail?.identity_number} - - - - Code - - - - {store.authentication.dataProfit.partner?.code} - - - - Status - - - - {store.authentication.dataProfit.is_active === true - ? "Aktif" - : "Inaktif"} - - - {store.authentication.userData.role === "Admin" && - store.authentication.dataProfit.roles?.name !== - "Admin Partner" && ( - - - Foto Identitas - - - - - - - - {store.authentication.dataProfit.roles?.name === - "Retail" && ( - - Foto Toko - - - {store.authentication.listImage - ? store.authentication.listImage.map( - (item, index) => ( - - ) - ) - : ""} - - - - )} - - )} - {store.authentication.userData.role === "Sales" && ( - - - Foto Identitas - - - - - - - - - Foto Toko - - - {store.authentication.listImage - ? store.authentication.listImage.map( - (item, index) => ( - - ) - ) - : ""} - - - - - )} - {store.authentication.userData.role === "Supervisor" && ( - - - Foto Identitas - - - - - - - - - )} - - - - - - - - - - - Saldo - - - - - {new Intl.NumberFormat("id-ID", { - style: "currency", - currency: "IDR", - }).format( - store.authentication.dataProfit.wallet || 0 - )} - - - - - - - - - - Keuntungan - - - - - {new Intl.NumberFormat("id-ID", { - style: "currency", - currency: "IDR", - }).format( - store.authentication.dataProfit?.profit || 0 - )} - - - - - - - - - - - - - - - {store.ui.mediaQuery.isDesktop && ( -
- - { - let pageNumber = page.current; - store.transaction.pageSize = page.pageSize; - store.transaction.page = pageNumber - 1; - modalLoader.setLoading(true); - await getData(); - modalLoader.setLoading(false); - }} - /> - - )} - {store.ui.mediaQuery.isMobile && ( -
- - { - store.transaction.pageSize = pageSize; - store.transaction.page = page - 1; - modalLoader.setLoading(true); - await getData(); - modalLoader.setLoading(false); - }, - pageSize: store.transaction.pageSize, - total: store.transaction.total_data, - current: store.transaction.page + 1, - style: { marginBottom: "1rem", marginRight: "1rem" }, - }} - dataSource={store.transaction.dataHistoryTopUp} - style={{ padding: 0 }} - renderItem={(item) => { - return ( -
- - -

- - Amount :{" "} - {new Intl.NumberFormat("id-ID", { - style: "currency", - currency: "IDR", - }).format(item.amount || 0)} - {" "} -
- - Transaction Date :{" "} - {format( - parseISO(item.transaction_date), - "dd-MM-yyyy hh:mm:ss" - )} - {" "} -
-

-
- } - /> - - -
- ); - }} - /> - - )} - - - {store.ui.mediaQuery.isDesktop && ( -
- -
1000 ? { - pageSizeOptions : [10, 20, 50, 100, 1000], - pageSize: store.transaction.pageSize, - total: store.transaction.total_data, - current: store.transaction.page + 1, - showSizeChanger: true, - simple: false, - } : - { - pageSize: store.transaction.pageSize, - total: store.transaction.total_data, - current: store.transaction.page + 1, - showSizeChanger: true, - simple: false, - } + {record?.status === true ? "INACTIVE" : "ACTIVE"} + + + + + ), + }, + ]; - } - onChange={async (page) => { - let pageNumber = page.current; - store.transaction.pageSize = page.pageSize; - store.transaction.page = pageNumber - 1; - modalLoader.setLoading(true); - await getData(); - modalLoader.setLoading(false); - }} - /> - - )} + if (store.authentication.userData.role === "Customer Service") columns.pop(); - {store.ui.mediaQuery.isMobile && ( -
- - { - store.transaction.pageSize = pageSize; - store.transaction.page = page - 1; - modalLoader.setLoading(true); - await getData(); - modalLoader.setLoading(false); - }, - pageSize: store.transaction.pageSize, - total: store.transaction.total_data, - current: store.transaction.page + 1, - style: { marginBottom: "1rem", marginRight: "1rem" }, - }} - dataSource={ - store.transaction.dataDetailHistoryTransactionDetailUser - } - style={{ padding: 0 }} - renderItem={(item) => { - return ( -
- - -

- Pembeli : {item.buyer}{" "} -
- Price : {item.price}
- - Tujuan : {item.transaction_destination} - {" "} -
- - Kode Transaksi : {item.transaction_code} - {" "} -
- - Status :{" "} - { - - {item.status === 1 - ? "Success" - : item.status === 0 - ? "Pending" - : "Failed"} - - } - {" "} -
- - No.Seri : {item.seri_number} - {" "} -
- - IDTrx Mitra :{" "} - {item.partner_transaction_code} - {" "} -
- - Transaction Date :{" "} - {format( - parseISO(item.created_at), - "dd-MM-yyyy hh:mm:ss" - )} - {" "} -
-

-
- } - /> - - -
- ); - }} - /> - - )} - - - - -
- - { - onSubmit(data); - }} - onCancel={() => { - setInitialData({}); - setVisibleModal(false); - }} - /> - { - //form.resetFields(); - store.transaction.filterStart = null; - store.transaction.filterEnd = null; - store.transaction.visibleModalFilterTransaction = false; - actionFilter === true - ? await store.transaction.getDataHistoryTopUp(id) - : await store.transaction.getDetailHistoryTransaction( - store.authentication.dataProfit.id + const deleteData = async (id) => { + try { + console.log(id); + modalLoader.setLoading(true); + await store.supplier.delete(id); + modalLoader.setLoading(false); + message.success("Data Berhasil Dihapus"); + history.push(LINKS.PRODUCT); + } catch (err) { + modalLoader.setLoading(false); + console.log("error", err); + message.error("Gagal menghapus"); + } + }; + + const handleDelete = (id) => { + Modal.confirm({ + title: "Are you sure delete this record?", + icon: , + okText: "Yes", + okType: "primary", + cancelText: "Batal", + onOk() { + return deleteData(id); + }, + onCancel() { + console.log("Batal"); + }, + }); + }; + + const handleCancel = () => { + setIdData(""); + store.supplier.visibleModalSupplier = false; + }; + + const handleSubmit = async (data) => { + console.log(data, "isi data2"); + if (idData !== "") { + try { + modalLoader.setLoading(true); + const response = await store.supplier.update(idData, data); + response?.body?.statusCode === 201 || response?.body?.statusCode === 200 + ? message.success( + response?.body?.message || "Berhasil Ubah Data Supplier" + ) + : message.error( + response?.body?.message || "Gagal Ubah Data Supplier" ); - //await store.transaction.getDetailHistoryTransaction(); - }} - > - -
- - - - - - - - - - - - { - setModalExport(false); - }} - > - - - - - - - - - - - + } catch (e) { + modalLoader.setLoading(false); + message.error(e.response?.body?.message || "Gagal Ubah Data Supplier"); + } + + modalLoader.setLoading(false); + store.supplier.visibleModalSupplier = false; + setIdData(""); + form.resetFields(); + } else { + try { + const response = await store.supplier.create(data); + if (response.status === 201) { + message.success( + response?.body?.message || "Berhasil Tambah Supplier" + ); + await store.supplier.getData(); + } else { + message.error(response?.body?.error || "Gagal Tambah Supplier", 3); + } + } catch (e) { + console.log("testingan"); + console.log(e.response, "testingan"); + console.log(e.result, "testingan1"); + if (e.response?.body?.error) { + message.error( + e.response.body.error + ? "Supplier Tersebut Sudah Terdaftar" + : e.response.body.error + ); + modalLoader.setLoading(false); + store.supplier.visibleModalSupplier = false; + return; + } + console.log(e, "apa errornya"); + message.error("Gagal Tambah Supplier"); + } + + modalLoader.setLoading(false); + store.supplier.visibleModalSupplier = false; + setIdData(""); + form.resetFields(); + await store.supplier.getData(); + } + }; + + return ( +
+ {store.ui.mediaQuery.isDesktop && ( +
{ + let pageNumber = page.current; + store.supplier.pageSize = page.pageSize; + store.supplier.page = pageNumber - 1; + modalLoader.setLoading(true); + await store.supplier.getData(); + modalLoader.setLoading(false); + }} + /> + )} + {store.ui.mediaQuery.isMobile && ( + { + store.supplier.pageSize = pageSize; + store.supplier.page = page - 1; + modalLoader.setLoading(true); + await store.supplier.getData(); + modalLoader.setLoading(false); + }, + pageSize: store.supplier.pageSize, + total: store.supplier.total_data, + current: store.supplier.page + 1, + style: { marginBottom: "1rem", marginRight: "1rem" }, + }} + dataSource={store.supplier.data} + style={{ padding: 0 }} + renderItem={(item) => { + return ( +
+ + +

+ Name : {item.name}
+ Saldo Supplier : {item.coa.amount} +
+ + Saldo System : {item.coa_undistribute.amount} + +
+ + + + + {item?.status === true ? " ACTIVE" : "INACTIVE"} + +

+

+
+ } + /> + + + + ); + }} + /> + )} + { + form.resetFields(); + handleCancel(); + }} + onOk={() => { + form + .validateFields() + .then((values) => { + console.log(values, "isi form"); + handleSubmit(values); + form.resetFields(); + }) + .catch((info) => { + console.error("Validate Failed:", info); + }); + }} + > +
+ + + + + + + + + + + + + + + + + + + {!idData && ( + + + + )} + +
+ + ); });