// @mui import { Box, Button, Card, Collapse, IconButton, MenuItem, Table, TableBody, TableCell, TableRow, TextField, Typography, Stack, Menu, ButtonGroup } from '@mui/material'; import KeyboardArrowDownIcon from '@mui/icons-material/KeyboardArrowDown'; import KeyboardArrowRightIcon from '@mui/icons-material/KeyboardArrowRight'; import AddIcon from '@mui/icons-material/Add'; import UploadIcon from '@mui/icons-material/Upload'; import CancelIcon from '@mui/icons-material/Cancel'; // hooks import React, { ChangeEvent, useEffect, useRef, useState } from 'react'; import { useSearchParams } from 'react-router-dom'; // components import axios from '../../utils/axios'; import { LaravelPaginatedData, LaravelPaginatedDataDefault } from '../../@types/paginated-data'; import DataTable from './LaravelTable'; export default function List() { const [searchParams, setSearchParams] = useSearchParams(); const [importResult, setImportResult] = useState(null); function SearchInput(props: any) { // SEARCH const searchInput = useRef(null); const [searchText, setSearchText] = useState(""); const handleSearchChange = (event: any) => { const newSearchText = event.target.value ?? '' setSearchText(newSearchText); } const handleSearchSubmit = (event: any) => { event.preventDefault(); props.onSearch({search: searchText }); // Trigger to Parent } useEffect(() => { // Trigger First Search setSearchText(searchParams.get('search') ?? ''); }, []) return (
); } function ImportForm(props: any) { // IMPORT // Create Button Menu const [anchorEl, setAnchorEl] = React.useState(null); const createMenu = Boolean(anchorEl); const importForm = useRef(null) const [currentImportFileName, setCurrentImportFileName] = useState(null) const handleClick = (event: React.MouseEvent) => { setAnchorEl(event.currentTarget); }; const handleClose = () => { setAnchorEl(null); }; const handleImportButton = () => { if (importForm?.current) { handleClose(); importForm.current ? importForm.current.click() : console.log('No File selected'); } else { alert('No file selected') } } const handleCancelImportButton = () => { importForm.current.value = ""; importForm.current.dispatchEvent(new Event("change", { bubbles: true })); } const handleImportChange = (event: any) => { if (event.target.files[0]) { setCurrentImportFileName(event.target.files[0].name) } else { setCurrentImportFileName(null); } } const handleUpload = () => { if (importForm.current?.files.length) { const formData = new FormData(); formData.append("file", importForm.current?.files[0]) axios.post(`corporates/${corporate_id}/import-plan-benefit`, formData ) .then(response => { handleCancelImportButton(); loadDataTableData(); setImportResult(response.data) // alert('Succesfully read '+ response.data.total_successed_row + ' with ' + response.data.total_failed_row + ' failed rows'); }) .catch(response => { enqueueSnackbar('Looks like something went wrong. Please check your data and try again. ' + response.message, { variant: 'error' }) }) } else { enqueueSnackbar('No File Selected', { variant: 'warning' }) } } return (
{( !currentImportFileName && {/*

kjasndkjandskjasndkjansdkjansd

*/} Import Download Template
)} {( currentImportFileName && )} {( importResult && Last Import Result Report : {importResult.result_file?.name ?? "-"} )}
); } // Dummy Default Data const [dataTableIsLoading, setDataTableLoading] = useState(true); const [dataTableData, setDataTableData] = useState(LaravelPaginatedDataDefault); const loadDataTableData = async (appliedFilter : any | null = null) => { setDataTableLoading(true); const filter = appliedFilter ? appliedFilter : Object.fromEntries([...searchParams.entries()]); const response = await axios.get('/master/drugs', { params: filter }); // console.log(response.data); setDataTableLoading(false); setDataTableData(response.data); } const applyFilter = async (searchFilter: {search: string}) => { await loadDataTableData(searchFilter); setSearchParams(searchFilter); } const handlePageChange = (event : ChangeEvent, value: number) : void => { const filter = Object.fromEntries([...searchParams.entries(), ["page", value]]); loadDataTableData(filter); setSearchParams(filter); } useEffect(() => { loadDataTableData(); }, []) const headStyle = { fontWeight: 'bold', }; // Called on every row to map the data to the columns function createData( data: Icd ): Icd { return { ...data, } } {/* ------------------ TABLE ROW ------------------ */} function Row(props: { row: ReturnType }) { const { row } = props; const [open, setOpen] = React.useState(false); return ( *': { borderBottom: 'unset' } }}> setOpen(!open)} > {open ? : } {row.type} {row.code} {row.name} {row.version} {/* COLLAPSIBLE ROW */} Description : {row.description} ); } {/* ------------------ END TABLE ROW ------------------ */} function TableContent() { return ( {/* ------------------ TABLE HEADER ------------------ */} Type Code Name Version Status Action {/* ------------------ END TABLE HEADER ------------------ */} {/* ------------------ TABLE ROW ------------------ */} {dataTableIsLoading ? ( Loading ) : ( dataTableData.data.length === 0 ? ( No Data ) : ( {dataTableData.data.map(row => ( ))} ) )} {/* ------------------ END TABLE ROW ------------------ */}
) } return ( } /> ); }