浏览代码

Add Invoice table

tags/Baseline_180220205_Frontend
MSI\2Fi 11 个月前
父节点
当前提交
5ea41296f3
共有 2 个文件被更改,包括 61 次插入29 次删除
  1. +2
    -2
      src/components/InvoiceSearch/InvoiceSearch.tsx
  2. +59
    -27
      src/components/InvoiceSearch/InvoiceTable.tsx

+ 2
- 2
src/components/InvoiceSearch/InvoiceSearch.tsx 查看文件

@@ -471,14 +471,14 @@ const InvoiceSearch: React.FC<Props> = ({ issuedInvoice, receivedInvoice, invoic
spacing={2} spacing={2}
> >
<ButtonGroup variant="contained"> <ButtonGroup variant="contained">
{/* <Button
<Button
startIcon={<AddIcon />} startIcon={<AddIcon />}
variant="outlined" variant="outlined"
component="label" component="label"
onClick={handleAddInvoiceClick} onClick={handleAddInvoiceClick}
> >
{t("Create Invoice")} {t("Create Invoice")}
</Button> */}
</Button>
<Button startIcon={<FileUploadIcon />} variant="contained" component="label"> <Button startIcon={<FileUploadIcon />} variant="contained" component="label">
<input <input
id='importExcel' id='importExcel'


+ 59
- 27
src/components/InvoiceSearch/InvoiceTable.tsx 查看文件

@@ -4,14 +4,23 @@ import { useTranslation } from "react-i18next";
import SearchResults, { Column } from "../SearchResults"; import SearchResults, { Column } from "../SearchResults";
import EditNote from "@mui/icons-material/EditNote"; import EditNote from "@mui/icons-material/EditNote";
import { moneyFormatter } from "@/app/utils/formatUtil" import { moneyFormatter } from "@/app/utils/formatUtil"
import { Button, ButtonGroup, Stack, Tab, Tabs, TabsProps, Dialog, DialogTitle, DialogContent, DialogContentText, DialogActions, TextField, CardContent, Typography, Divider, Card, Box } from "@mui/material";
import { Button, ButtonGroup, Stack, Tab, Tabs, TabsProps, Dialog, DialogTitle, DialogContent, DialogContentText, DialogActions, TextField, CardContent, Typography, Divider, Card, Box, Autocomplete, MenuItem } from "@mui/material";
import FileUploadIcon from '@mui/icons-material/FileUpload'; import FileUploadIcon from '@mui/icons-material/FileUpload';
import { Add, Check, Close, Delete } from "@mui/icons-material"; import { Add, Check, Close, Delete } from "@mui/icons-material";
import { deleteInvoice, importIssuedInovice, importReceivedInovice, updateInvoice } from "@/app/api/invoices/actions"; import { deleteInvoice, importIssuedInovice, importReceivedInovice, updateInvoice } from "@/app/api/invoices/actions";
import { deleteDialog, errorDialogWithContent, successDialog } from "../Swal/CustomAlerts"; import { deleteDialog, errorDialogWithContent, successDialog } from "../Swal/CustomAlerts";
import { invoiceList, issuedInvoiceList, issuedInvoiceSearchForm, receivedInvoiceList, receivedInvoiceSearchForm } from "@/app/api/invoices"; import { invoiceList, issuedInvoiceList, issuedInvoiceSearchForm, receivedInvoiceList, receivedInvoiceSearchForm } from "@/app/api/invoices";
import EditOutlinedIcon from '@mui/icons-material/EditOutlined'; import EditOutlinedIcon from '@mui/icons-material/EditOutlined';
import { GridCellParams, GridColDef, GridEventListener, GridRowId, GridRowModel, GridRowModes, GridRowModesModel } from "@mui/x-data-grid";
import {
GridCellParams,
GridColDef,
GridEventListener,
GridRowId,
GridRowModel,
GridRowModes,
GridRowModesModel,
GridRenderEditCellParams,
} from "@mui/x-data-grid";
import { useGridApiRef } from "@mui/x-data-grid"; import { useGridApiRef } from "@mui/x-data-grid";
import StyledDataGrid from "../StyledDataGrid"; import StyledDataGrid from "../StyledDataGrid";


@@ -91,29 +100,37 @@ const InvoiceTable: React.FC = () => {
// console.log(error) // console.log(error)
// Test for warnings // Test for warnings
apiRef.current.updateRows([{ id, _error: error }]);
// apiRef.current.updateRows([{ id, _error: error }]);
return error; return error;
}, },
[apiRef],
[],
); );


const handleEditStop = useCallback<GridEventListener<"rowEditStop">>( const handleEditStop = useCallback<GridEventListener<"rowEditStop">>(
(params, event) => { (params, event) => {
// console.log(params.id)
if (validateRow(params.id) !== undefined || !validateRow(params.id)) {
const row = apiRef.current.getRowWithUpdatedValues(
params.id,
"",
)
console.log(validateRow(params.id) !== undefined)
console.log(!validateRow(params.id))
if (validateRow(params.id) !== undefined && !validateRow(params.id)) {
setRowModesModel((model) => ({ setRowModesModel((model) => ({
...model, ...model,
[params.id]: { mode: GridRowModes.View}, [params.id]: { mode: GridRowModes.View},
})); }));
const row = apiRef.current.getRowWithUpdatedValues(
params.id,
"",
)
console.log(row) console.log(row)
setSelectedRow((row) => [...row] as any[]) setSelectedRow((row) => [...row] as any[])
event.defaultMuiPrevented = true; event.defaultMuiPrevented = true;
}else{
console.log(row)
const error = validateRow(params.id)
setSelectedRow((row) => {
const updatedRow = row.map(r => r.id === params.id ? { ...r, _error: error } : r);
return updatedRow;
})
} }
// console.log(row) // console.log(row)
}, },
@@ -157,8 +174,9 @@ const InvoiceTable: React.FC = () => {
console.log(newRow) console.log(newRow)


setSelectedRow((es) => setSelectedRow((es) =>
es.map((e) => (e.id === rowToSave.id ? rowToSave : e))
es.map((e) => (e.id === originalRow.id ? rowToSave : e))
); );
console.log(rowToSave)
return rowToSave; return rowToSave;
}, },
[validateRow], [validateRow],
@@ -171,7 +189,7 @@ const InvoiceTable: React.FC = () => {
(updateError: ProcessRowUpdateError) => { (updateError: ProcessRowUpdateError) => {
const errors = updateError.errors; const errors = updateError.errors;
const oldRow = updateError.row; const oldRow = updateError.row;
// console.log(errors)
apiRef.current.updateRows([{ ...oldRow, _error: errors }]); apiRef.current.updateRows([{ ...oldRow, _error: errors }]);
}, },
[apiRef] [apiRef]
@@ -186,9 +204,23 @@ const InvoiceTable: React.FC = () => {
const editCombinedColumns = useMemo<GridColDef[]>( const editCombinedColumns = useMemo<GridColDef[]>(
() => [ () => [
{ field: "invoiceNo", headerName: t("Invoice No"), editable: true, flex: 0.5 }, { field: "invoiceNo", headerName: t("Invoice No"), editable: true, flex: 0.5 },
{ field: "projectCode", headerName: t("Project Code"), editable: false, flex: 0.3 },
// { field: "projectName", headerName: t("Project Name"), flex: 1 },
// { field: "team", headerName: t("Team"), flex: 0.2 },
{ field: "projectCode",
headerName: t("Project Code"),
editable: true,
flex: 0.3,
renderEditCell(params: GridRenderEditCellParams<invoiceListRow, number>){
return(
<Autocomplete
disablePortal
options={[]}
sx={{width: '100%'}}
renderInput={(params) => <TextField {...params} />}
/>

)
}
},
{ field: "issuedDate", { field: "issuedDate",
headerName: t("Issue Date"), headerName: t("Issue Date"),
editable: true, editable: true,
@@ -222,18 +254,18 @@ const editCombinedColumns = useMemo<GridColDef[]>(
) )


const footer = ( const footer = (
<Box display="flex" gap={2} alignItems="center">
<Button
disableRipple
variant="outlined"
startIcon={<Add />}
onClick={addRow}
size="small"
>
{t("Create Invoice")}
</Button>
</Box>
);
<Box display="flex" gap={2} alignItems="center">
<Button
disableRipple
variant="outlined"
startIcon={<Add />}
onClick={addRow}
size="small"
>
{t("Create Invoice")}
</Button>
</Box>
);


return ( return (
<> <>


正在加载...
取消
保存