| @@ -18,7 +18,7 @@ const Companys: React.FC<Props> = async ({searchParams}) => { | |||||
| return( | return( | ||||
| <> | <> | ||||
| <Typography variant="h4">{t("Create Company")}</Typography> | |||||
| <Typography variant="h4">{t("Edit Company")}</Typography> | |||||
| <I18nProvider namespaces={["companys"]}> | <I18nProvider namespaces={["companys"]}> | ||||
| <CreateCompany isEdit={true} companyId={companyId} /> | <CreateCompany isEdit={true} companyId={companyId} /> | ||||
| </I18nProvider> | </I18nProvider> | ||||
| @@ -3,6 +3,7 @@ | |||||
| import { serverFetchJson, serverFetchWithNoContent } from "@/app/utils/fetchUtil"; | import { serverFetchJson, serverFetchWithNoContent } from "@/app/utils/fetchUtil"; | ||||
| import { BASE_API_URL } from "@/config/api"; | import { BASE_API_URL } from "@/config/api"; | ||||
| import { Dayjs } from "dayjs"; | import { Dayjs } from "dayjs"; | ||||
| import { revalidateTag } from "next/cache"; | |||||
| import { cache } from "react"; | import { cache } from "react"; | ||||
| export interface comboProp { | export interface comboProp { | ||||
| @@ -49,17 +50,21 @@ export interface EditCompanyInputs { | |||||
| } | } | ||||
| export const saveCompany = async (data: CreateCompanyInputs) => { | export const saveCompany = async (data: CreateCompanyInputs) => { | ||||
| return serverFetchJson(`${BASE_API_URL}/companys/new`, { | |||||
| const newCompany = serverFetchJson(`${BASE_API_URL}/companys/new`, { | |||||
| method: "POST", | method: "POST", | ||||
| body: JSON.stringify(data), | body: JSON.stringify(data), | ||||
| headers: { "Content-Type": "application/json" }, | headers: { "Content-Type": "application/json" }, | ||||
| }); | }); | ||||
| revalidateTag("companys"); | |||||
| return newCompany | |||||
| }; | }; | ||||
| export const fetchCompanyCombo = cache(async () => { | export const fetchCompanyCombo = cache(async () => { | ||||
| return serverFetchJson<combo>(`${BASE_API_URL}/companys/combo`, { | return serverFetchJson<combo>(`${BASE_API_URL}/companys/combo`, { | ||||
| next: { tags: ["company"] }, | next: { tags: ["company"] }, | ||||
| }); | }); | ||||
| }); | }); | ||||
| export const deleteCompany = async (id: number) => { | export const deleteCompany = async (id: number) => { | ||||
| @@ -71,5 +76,6 @@ export const deleteCompany = async (id: number) => { | |||||
| }, | }, | ||||
| ); | ); | ||||
| revalidateTag("companys"); | |||||
| return department | return department | ||||
| }; | }; | ||||
| @@ -28,7 +28,7 @@ export const fetchCompanyDetails = cache(async (companyId: string) => { | |||||
| return serverFetchJson<EditCompanyInputs>( | return serverFetchJson<EditCompanyInputs>( | ||||
| `${BASE_API_URL}/companys/companyDetails/${companyId}`, | `${BASE_API_URL}/companys/companyDetails/${companyId}`, | ||||
| { | { | ||||
| next: { tags: [`departmentDetail${companyId}`] }, | |||||
| next: { tags: [`departmentDetail`] }, | |||||
| }, | }, | ||||
| ); | ); | ||||
| }); | }); | ||||
| @@ -2,6 +2,7 @@ | |||||
| import { serverFetchJson, serverFetchWithNoContent } from "@/app/utils/fetchUtil"; | import { serverFetchJson, serverFetchWithNoContent } from "@/app/utils/fetchUtil"; | ||||
| import { BASE_API_URL } from "@/config/api"; | import { BASE_API_URL } from "@/config/api"; | ||||
| import { revalidateTag } from "next/cache"; | |||||
| import { cache } from "react"; | import { cache } from "react"; | ||||
| @@ -21,11 +22,14 @@ export interface CreateDepartmentInputs { | |||||
| } | } | ||||
| export const saveDepartment = async (data: CreateDepartmentInputs) => { | export const saveDepartment = async (data: CreateDepartmentInputs) => { | ||||
| return serverFetchJson(`${BASE_API_URL}/departments/new`, { | |||||
| const newDepartment = serverFetchJson(`${BASE_API_URL}/departments/new`, { | |||||
| method: "POST", | method: "POST", | ||||
| body: JSON.stringify(data), | body: JSON.stringify(data), | ||||
| headers: { "Content-Type": "application/json" }, | headers: { "Content-Type": "application/json" }, | ||||
| }); | }); | ||||
| revalidateTag("departments") | |||||
| return newDepartment | |||||
| }; | }; | ||||
| export const deleteDepartment = async (id: number) => { | export const deleteDepartment = async (id: number) => { | ||||
| @@ -37,6 +41,7 @@ export const deleteDepartment = async (id: number) => { | |||||
| }, | }, | ||||
| ); | ); | ||||
| revalidateTag("departments") | |||||
| return department | return department | ||||
| }; | }; | ||||
| @@ -4,6 +4,7 @@ import { serverFetchJson, serverFetchWithNoContent } from "@/app/utils/fetchUtil | |||||
| import { BASE_API_URL } from "@/config/api"; | import { BASE_API_URL } from "@/config/api"; | ||||
| import { cache } from "react"; | import { cache } from "react"; | ||||
| import { PositionResult } from "."; | import { PositionResult } from "."; | ||||
| import { revalidateTag } from "next/cache"; | |||||
| export interface comboProp { | export interface comboProp { | ||||
| id: any; | id: any; | ||||
| @@ -30,19 +31,25 @@ export interface EditPositionInputs { | |||||
| } | } | ||||
| export const savePosition = async (data: CreatePositionInputs) => { | export const savePosition = async (data: CreatePositionInputs) => { | ||||
| return serverFetchJson(`${BASE_API_URL}/positions/new`, { | |||||
| const newPosition = serverFetchJson(`${BASE_API_URL}/positions/new`, { | |||||
| method: "POST", | method: "POST", | ||||
| body: JSON.stringify(data), | body: JSON.stringify(data), | ||||
| headers: { "Content-Type": "application/json" }, | headers: { "Content-Type": "application/json" }, | ||||
| }); | }); | ||||
| revalidateTag("positions") | |||||
| return newPosition | |||||
| }; | }; | ||||
| export const editPosition = async (data: EditPositionInputs) => { | export const editPosition = async (data: EditPositionInputs) => { | ||||
| return serverFetchJson(`${BASE_API_URL}/positions/new`, { | |||||
| const editPostion = serverFetchJson(`${BASE_API_URL}/positions/new`, { | |||||
| method: "POST", | method: "POST", | ||||
| body: JSON.stringify(data), | body: JSON.stringify(data), | ||||
| headers: { "Content-Type": "application/json" }, | headers: { "Content-Type": "application/json" }, | ||||
| }); | }); | ||||
| revalidateTag("positions") | |||||
| return editPostion | |||||
| }; | }; | ||||
| export const deletePosition = async (id: number) => { | export const deletePosition = async (id: number) => { | ||||
| @@ -54,6 +61,7 @@ export const deletePosition = async (id: number) => { | |||||
| }, | }, | ||||
| ); | ); | ||||
| revalidateTag("positions") | |||||
| return position | return position | ||||
| }; | }; | ||||
| @@ -44,7 +44,7 @@ const CompanyDetails: React.FC<Props> = ({ | |||||
| getValues, | getValues, | ||||
| } = useFormContext<CreateCompanyInputs>(); | } = useFormContext<CreateCompanyInputs>(); | ||||
| console.log(content) | |||||
| // console.log(content) | |||||
| useEffect(() => { | useEffect(() => { | ||||
| setValue("normalHourFrom", convertTimeArrayToString(content.normalHourFrom, "HH:mm:ss", false)); | setValue("normalHourFrom", convertTimeArrayToString(content.normalHourFrom, "HH:mm:ss", false)); | ||||
| @@ -11,8 +11,8 @@ type Props = CreateCompanyProps | EditCompanyProps; | |||||
| const CreateCompanyWrapper: React.FC<Props> = async (props) => { | const CreateCompanyWrapper: React.FC<Props> = async (props) => { | ||||
| console.log(props) | |||||
| // console.log(props) | |||||
| const companyDetails = props.isEdit | const companyDetails = props.isEdit | ||||
| ? await fetchCompanyDetails(props.companyId!) | ? await fetchCompanyDetails(props.companyId!) | ||||
| : undefined; | : undefined; | ||||