149 lines
4.1 KiB
TypeScript
149 lines
4.1 KiB
TypeScript
import type { CommonTableProps } from "@/app/store/common/type/header";
|
|
import { fetchType, getFetchWithCount, putFectch } from "@/components/lib/api";
|
|
import type { DemandCompType } from "@common/business_components/ui/sdmInsertForm/form";
|
|
import { coSttHeadListExport, coSttNodeListExport } from "./headList";
|
|
import toast from "react-hot-toast";
|
|
|
|
// 테이블 헤드 리스트
|
|
const coSttNodeList = coSttNodeListExport;
|
|
const coSttHeadList = coSttHeadListExport;
|
|
const coSttnRes: DemandCompType[] = [];
|
|
|
|
|
|
export type coSttnState = {
|
|
coSttn: {
|
|
coSttnRes: DemandCompType[];
|
|
coSttHeadList: CommonTableProps[];
|
|
coSttNodeList: CommonTableProps[];
|
|
excelList: [];
|
|
isInit: boolean;
|
|
coSttnResCount: number;
|
|
};
|
|
};
|
|
|
|
type coSttnActions = {
|
|
coSttnInit: (pageNo: string, pageCnt: string, con: string) => void;
|
|
coSttnSearch: (pageNo: string, pageCnt: string, con: string) => void;
|
|
coSttnTxtSearch: (pageNo: string, pageCnt: string, con: string, txt: string) => void;
|
|
coSttnPwInit: (dmdInfoId: string) => void;
|
|
};
|
|
|
|
export type coSttnType = coSttnState & coSttnActions;
|
|
|
|
export const coSttnStateExport: coSttnState = {
|
|
coSttn: {
|
|
coSttHeadList: coSttHeadList,
|
|
coSttNodeList: coSttNodeList,
|
|
coSttnRes: coSttnRes,
|
|
excelList: [],
|
|
isInit: false,
|
|
coSttnResCount: 0,
|
|
},
|
|
};
|
|
|
|
|
|
export const coSttnActionsExport: (set: any) => coSttnActions = (
|
|
set: any
|
|
) => {
|
|
return {
|
|
coSttnInit: async (pageNo: string, pageCnt: string, con: string) => {
|
|
try {
|
|
|
|
const coSttnRes = await getFetchWithCount(
|
|
fetchType.WR,
|
|
`/reuseFc/request/${pageNo}/${pageCnt}/${con}`
|
|
);
|
|
|
|
set((state: coSttnState) => {
|
|
return {
|
|
...state,
|
|
coSttn: {
|
|
...state.coSttn,
|
|
coSttnRes: coSttnRes.data,
|
|
isInit: false,
|
|
coSttnResCount: coSttnRes.count,
|
|
},
|
|
};
|
|
});
|
|
} catch (e) {
|
|
console.log(e)
|
|
}
|
|
},
|
|
coSttnSearch: async (pageNo: string, pageCnt: string, con: string) => {
|
|
try {
|
|
const coSttnRes = await getFetchWithCount(
|
|
fetchType.WR,
|
|
`/reuseFc/request/${pageNo}/${pageCnt}/${con}`
|
|
);
|
|
if (Number(pageCnt) >= 10000) {
|
|
set((state: coSttnState) => {
|
|
return {
|
|
...state,
|
|
coSttn: {
|
|
...state.coSttn,
|
|
excelList: coSttnRes.data,
|
|
//isInit: false,
|
|
},
|
|
};
|
|
});
|
|
} else
|
|
set((state: coSttnState) => {
|
|
return {
|
|
...state,
|
|
coSttn: {
|
|
...state.coSttn,
|
|
coSttnRes: coSttnRes.data,
|
|
isInit: false,
|
|
coSttnResCount: coSttnRes.count,
|
|
},
|
|
};
|
|
});
|
|
} catch (erTxt) {
|
|
console.log("error", erTxt);
|
|
}
|
|
},
|
|
coSttnTxtSearch: async (pageNo: string, pageCnt: string, con: string, txt: string) => {
|
|
try {
|
|
const coSttnRes = await getFetchWithCount(
|
|
fetchType.WR,
|
|
`/reuseFc/request/${pageNo}/${pageCnt}/${con}/${txt}`)
|
|
set((state: coSttnState) => {
|
|
return {
|
|
...state,
|
|
coSttn: {
|
|
...state.coSttn,
|
|
coSttnRes: coSttnRes.data,
|
|
coSttnResCount: coSttnRes.count,
|
|
isInit: false,
|
|
}
|
|
}
|
|
})
|
|
} catch (erTxt) {
|
|
console.log("error", erTxt);
|
|
}
|
|
},
|
|
coSttnPwInit: async (dmdInfoId: string) => {
|
|
try {
|
|
const response = await putFectch(`/reuseFc/request/chgPassword/${dmdInfoId}`,[])
|
|
if (response.status === 200) {
|
|
toast.success('비밀번호가 초기화 되었습니다.')
|
|
} else {
|
|
toast.error('비밀번호 초기화에 실패하였습니다')
|
|
}
|
|
set((state: coSttnState) => {
|
|
return {
|
|
...state,
|
|
coSttn: {
|
|
...state.coSttn,
|
|
isInit: false,
|
|
}
|
|
}
|
|
});
|
|
} catch (err) {
|
|
console.log(err);
|
|
toast.error('비밀번호 초기화에 실패하였습니다.')
|
|
|
|
}
|
|
}
|
|
}
|
|
} |