|
@@ -5,8 +5,8 @@ import { FileUpload } from "@mui/icons-material"; |
|
|
import { Button, Grid, Stack } from "@mui/material"; |
|
|
import { Button, Grid, Stack } from "@mui/material"; |
|
|
import React, { ChangeEvent, useCallback } from "react"; |
|
|
import React, { ChangeEvent, useCallback } from "react"; |
|
|
import { useTranslation } from "react-i18next"; |
|
|
import { useTranslation } from "react-i18next"; |
|
|
import { errorDialogWithContent, successDialog, successDialogWithContent } from "../Swal/CustomAlerts"; |
|
|
|
|
|
import { importTimesheets } from "@/app/api/timesheets/actions"; |
|
|
|
|
|
|
|
|
import { errorDialogWithContent, submitDialog, successDialog, successDialogWithContent } from "../Swal/CustomAlerts"; |
|
|
|
|
|
import { importLeaves, importTimesheets, rearrangeTimesheets } from "@/app/api/timesheets/actions"; |
|
|
|
|
|
|
|
|
interface Props { |
|
|
interface Props { |
|
|
} |
|
|
} |
|
@@ -34,9 +34,12 @@ const ExcelFileImport: React.FC<Props> = async ({ }) => { |
|
|
case "importTimesheet": |
|
|
case "importTimesheet": |
|
|
response = await importTimesheets(formData) |
|
|
response = await importTimesheets(formData) |
|
|
break; |
|
|
break; |
|
|
|
|
|
case "importLeave": |
|
|
|
|
|
response = await importLeaves(formData) |
|
|
|
|
|
break; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if (response === "Import Excel success") { |
|
|
|
|
|
|
|
|
if (response.includes("Import Excel success")) { |
|
|
successDialogWithContent(t("Import Success"), t(`${response}`), t) |
|
|
successDialogWithContent(t("Import Success"), t(`${response}`), t) |
|
|
} else { |
|
|
} else { |
|
|
errorDialogWithContent(t("Import Fail"), t(`${response}`), t) |
|
|
errorDialogWithContent(t("Import Fail"), t(`${response}`), t) |
|
@@ -52,6 +55,37 @@ const ExcelFileImport: React.FC<Props> = async ({ }) => { |
|
|
return |
|
|
return |
|
|
}, []) |
|
|
}, []) |
|
|
|
|
|
|
|
|
|
|
|
const handleButtonClick = useCallback(async (event: React.MouseEvent<HTMLElement>) => { |
|
|
|
|
|
try { |
|
|
|
|
|
|
|
|
|
|
|
const targetId = event.currentTarget.id |
|
|
|
|
|
submitDialog(async () => { |
|
|
|
|
|
let response: String = "" |
|
|
|
|
|
|
|
|
|
|
|
switch (targetId) { |
|
|
|
|
|
case "rearrangeTimesheet": |
|
|
|
|
|
response = await rearrangeTimesheets() |
|
|
|
|
|
break; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (response.includes("Rearrange success")) { |
|
|
|
|
|
successDialogWithContent(t("Rearrange Success"), t(`${response}`), t) |
|
|
|
|
|
} else { |
|
|
|
|
|
errorDialogWithContent(t("Rearrange Fail"), t(`${response}`), t) |
|
|
|
|
|
} |
|
|
|
|
|
}, t, |
|
|
|
|
|
{ |
|
|
|
|
|
title: "Do you want to rearrange?", |
|
|
|
|
|
confirmButtonText: "Rearrange" |
|
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
} catch (err) { |
|
|
|
|
|
console.log(err) |
|
|
|
|
|
return false |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
}, []) |
|
|
|
|
|
|
|
|
return ( |
|
|
return ( |
|
|
<> |
|
|
<> |
|
|
<Grid container rowGap={1.5}> |
|
|
<Grid container rowGap={1.5}> |
|
@@ -93,6 +127,37 @@ const ExcelFileImport: React.FC<Props> = async ({ }) => { |
|
|
{t("Import Timesheet")} |
|
|
{t("Import Timesheet")} |
|
|
</Button> |
|
|
</Button> |
|
|
</Grid> |
|
|
</Grid> |
|
|
|
|
|
<Grid container> |
|
|
|
|
|
<Button |
|
|
|
|
|
id="rearrangeTimesheet" |
|
|
|
|
|
variant="contained" |
|
|
|
|
|
color="error" |
|
|
|
|
|
startIcon={<FileUpload />} |
|
|
|
|
|
component="label" |
|
|
|
|
|
onClick={handleButtonClick} |
|
|
|
|
|
> |
|
|
|
|
|
{t("Rearrange Timesheet")} |
|
|
|
|
|
</Button> |
|
|
|
|
|
</Grid> |
|
|
|
|
|
<Grid container> |
|
|
|
|
|
<Button |
|
|
|
|
|
variant="contained" |
|
|
|
|
|
color="info" |
|
|
|
|
|
startIcon={<FileUpload />} |
|
|
|
|
|
component="label" |
|
|
|
|
|
> |
|
|
|
|
|
<input |
|
|
|
|
|
id='importLeave' |
|
|
|
|
|
type='file' |
|
|
|
|
|
accept='.xlsx, .csv' |
|
|
|
|
|
hidden |
|
|
|
|
|
onChange={(event) => { |
|
|
|
|
|
handleExcelFileImportClick(event) |
|
|
|
|
|
}} |
|
|
|
|
|
/> |
|
|
|
|
|
{t("Import Leave")} |
|
|
|
|
|
</Button> |
|
|
|
|
|
</Grid> |
|
|
</Grid> |
|
|
</Grid> |
|
|
</> |
|
|
</> |
|
|
); |
|
|
); |
|
|