浏览代码

[PO] add mail template function

master
cyril.tsui 4 天前
父节点
当前提交
08b6cfb505
共有 5 个文件被更改,包括 41 次插入5 次删除
  1. +17
    -0
      src/app/api/mailTemplate/actions.ts
  2. +6
    -1
      src/app/utils/fetchUtil.ts
  3. +10
    -1
      src/components/PoDetail/PoDetail.tsx
  4. +6
    -3
      src/components/PoDetail/PoInputGrid.tsx
  5. +2
    -0
      src/components/PoDetail/QcStockInModalVer2.tsx

+ 17
- 0
src/app/api/mailTemplate/actions.ts 查看文件

@@ -0,0 +1,17 @@
"use server";

import { serverFetchBlob } from "@/app/utils/fetchUtil";
import { BASE_API_URL } from "@/config/api";
import { cache } from "react";

export const getMailTemplateForStockInLine = cache(async (stockInLineId: number) => {
console.log("stockInLineId", stockInLineId)
return serverFetchBlob(`${BASE_API_URL}/mailTemplates/getMailTemplateForStockInLine/${stockInLineId}`,
{
method: "GET",
headers: { "Content-Type": "application/json" },
next: {
tags: ["mailTemplateForStockInLine"],
},
})
})

+ 6
- 1
src/app/utils/fetchUtil.ts 查看文件

@@ -3,6 +3,11 @@ import { getServerSession } from "next-auth";
import { headers } from "next/headers";
import { redirect } from "next/navigation";

export interface BlobResponse {
filename: string;
blobValue: Uint8Array;
}

export interface Pageable {
pageSize?: number;
pageNum?: number;
@@ -86,7 +91,7 @@ export async function serverFetchJson<T>(...args: FetchParams) {
}
}

export async function serverFetchBlob<T>(...args: FetchParams) {
export async function serverFetchBlob<T extends BlobResponse>(...args: FetchParams) {
const response = await serverFetch(...args);

if (response.ok) {


+ 10
- 1
src/components/PoDetail/PoDetail.tsx 查看文件

@@ -68,7 +68,7 @@ import PoQcStockInModal from "./PoQcStockInModal";
import QrModal from "./QrModal";
import { PlayArrow } from "@mui/icons-material";
import DoneIcon from "@mui/icons-material/Done";
import { getCustomWidth } from "@/app/utils/commonUtil";
import { downloadFile, getCustomWidth } from "@/app/utils/commonUtil";
import PoInfoCard from "./PoInfoCard";
import { decimalFormatter, integerFormatter } from "@/app/utils/formatUtil";
import { List, ListItem, ListItemButton, ListItemText, Divider } from "@mui/material";
@@ -78,6 +78,7 @@ import { AdapterDayjs } from "@mui/x-date-pickers/AdapterDayjs";
import { DatePicker, LocalizationProvider, zhHK } from "@mui/x-date-pickers";
import { debounce } from "lodash";
import LoadingComponent from "../General/LoadingComponent";
import { getMailTemplateForStockInLine } from "@/app/api/mailTemplate/actions";
//import { useRouter } from "next/navigation";


@@ -333,6 +334,13 @@ const PoDetail: React.FC<Props> = ({ po, qc, warehouse }) => {
setPurchaseOrder(newPo);
}, [purchaseOrder.id]);

const handleMailTemplateForStockInLine = useCallback(async (stockInLineId: number) => {
const response = await getMailTemplateForStockInLine(stockInLineId)
if (response) {
downloadFile(new Uint8Array(response.blobValue), response.filename);
}
}, [])

useEffect(() => {
setRows(purchaseOrder.pol || []);
}, [purchaseOrder]);
@@ -849,6 +857,7 @@ const PoDetail: React.FC<Props> = ({ po, qc, warehouse }) => {
itemDetail={selectedRow}
warehouse={warehouse}
fetchPoDetail={fetchPoDetail}
handleMailTemplateForStockInLine={handleMailTemplateForStockInLine}
/>
</Box>
</TableCell>


+ 6
- 3
src/components/PoDetail/PoInputGrid.tsx 查看文件

@@ -74,6 +74,7 @@ interface Props {
stockInLine: StockInLine[];
warehouse: WarehouseResult[];
fetchPoDetail: (poId: string) => void;
handleMailTemplateForStockInLine: (stockInLineId: number) => void;
}

export type StockInLineEntryError = {
@@ -112,7 +113,8 @@ function PoInputGrid({
itemDetail,
stockInLine,
warehouse,
fetchPoDetail
fetchPoDetail,
handleMailTemplateForStockInLine
}: Props) {
console.log(itemDetail);
const { t } = useTranslation("purchaseOrder");
@@ -595,7 +597,7 @@ const closeNewModal = useCallback(() => {
variant="contained"
color="primary"
sx={{ width: '150px' }}
// onClick={formProps.handleSubmit(onSubmitEmailSupplier)}
onClick={() => handleMailTemplateForStockInLine(params.row.id as number)}
>
{t("email supplier")}
</Button>}
@@ -604,7 +606,7 @@ const closeNewModal = useCallback(() => {
// color: "primary.main",
// marginRight: 1,
}}
onClick={handleNewQC(params.row.id, params)}
// onClick={handleNewQC(params.row.id, params)}
color="inherit"
key="edit"
/>,
@@ -914,6 +916,7 @@ const closeNewModal = useCallback(() => {
open={newOpen}
onClose={closeNewModal}
itemDetail={modalInfo}
handleMailTemplateForStockInLine={handleMailTemplateForStockInLine}
/>
</>
)


+ 2
- 0
src/components/PoDetail/QcStockInModalVer2.tsx 查看文件

@@ -54,6 +54,7 @@ interface CommonProps extends Omit<ModalProps, "children"> {
qc?: QcItemWithChecks[];
warehouse?: any[];
// type: "qc" | "stockIn" | "escalation" | "putaway" | "reject";
handleMailTemplateForStockInLine: (stockInLineId: number) => void;
}
interface Props extends CommonProps {
itemDetail: StockInLine & { qcResult?: PurchaseQcResult[] };
@@ -69,6 +70,7 @@ const PoQcStockInModalVer2: React.FC<Props> = ({
setItemDetail,
qc,
warehouse,
handleMailTemplateForStockInLine,
}) => {
const {
t,


正在加载...
取消
保存