fix(dm): fixes to validate auth before submiting incase someone stays on the page to long
This commit is contained in:
@@ -3,53 +3,72 @@ import ForecastImport from "./ForecastImport";
|
|||||||
import OrderImport from "./OrderImport";
|
import OrderImport from "./OrderImport";
|
||||||
|
|
||||||
export default function DMButtons() {
|
export default function DMButtons() {
|
||||||
const { settings } = useSettingStore();
|
const { settings } = useSettingStore();
|
||||||
const testServers = ["test1", "test2", "test3"];
|
const testServers = ["test1", "test2", "test3"];
|
||||||
const plantToken = settings.filter((n) => n.name === "plantToken");
|
const plantToken = settings.filter((n) => n.name === "plantToken");
|
||||||
//console.log(plantToken);
|
|
||||||
return (
|
//console.log(plantToken);
|
||||||
<div className="flex flex-row-reverse gap-1">
|
return (
|
||||||
<OrderImport fileType={"macro"} name={"Macro Import"} />
|
<div className="flex flex-row-reverse gap-1">
|
||||||
{/* dev and testserver sees all */}
|
<OrderImport fileType={"macro"} name={"Macro Import"} />
|
||||||
{testServers.includes(plantToken[0]?.value) && (
|
{/* dev and testserver sees all */}
|
||||||
<div className="flex flex-row gap-2">
|
{testServers.includes(plantToken[0]?.value) && (
|
||||||
<OrderImport fileType={"abbott"} name={"Abbott truck list"} />
|
<div className="flex flex-row gap-2">
|
||||||
<OrderImport fileType={"energizer"} name={"Energizer Truck List"} />
|
<OrderImport
|
||||||
<ForecastImport fileType={"loreal"} name={"VMI Import"} />
|
fileType={"abbott"}
|
||||||
<ForecastImport fileType={"pg"} name={"P&G"} />
|
name={"Abbott truck list"}
|
||||||
<ForecastImport fileType={"energizer"} name={"Energizer Forecast"} />
|
/>
|
||||||
</div>
|
<OrderImport
|
||||||
)}
|
fileType={"energizer"}
|
||||||
{plantToken[0]?.value === "usday1" && (
|
name={"Energizer Truck List"}
|
||||||
<div className="flex flex-row gap-2">
|
/>
|
||||||
<OrderImport fileType={"abbott"} name={"Abbott truck list"} />
|
<ForecastImport fileType={"loreal"} name={"VMI Import"} />
|
||||||
<OrderImport fileType={"energizer"} name={"Energizer Truck List"} />
|
<ForecastImport fileType={"pg"} name={"P&G"} />
|
||||||
<ForecastImport fileType={"energizer"} name={"Energizer Forecast"} />
|
<ForecastImport
|
||||||
</div>
|
fileType={"energizer"}
|
||||||
)}
|
name={"Energizer Forecast"}
|
||||||
{plantToken[0]?.value === "usflo1" && (
|
/>
|
||||||
<div className="flex flex-row gap-2">
|
</div>
|
||||||
<ForecastImport fileType={"loreal"} name={"VMI Import"} />
|
)}
|
||||||
</div>
|
{plantToken[0]?.value === "usday1" && (
|
||||||
)}
|
<div className="flex flex-row gap-2">
|
||||||
{plantToken[0]?.value === "usstp1" && (
|
<OrderImport
|
||||||
<div className="flex flex-row gap-2"></div>
|
fileType={"abbott"}
|
||||||
)}
|
name={"Abbott truck list"}
|
||||||
{plantToken[0]?.value === "usiow1" && (
|
/>
|
||||||
<div className="flex flex-row gap-2">
|
<OrderImport
|
||||||
<ForecastImport fileType={"pg"} name={"P&G"} />
|
fileType={"energizer"}
|
||||||
</div>
|
name={"Energizer Truck List"}
|
||||||
)}
|
/>
|
||||||
{plantToken[0]?.value === "usiow2" && (
|
<ForecastImport
|
||||||
<div className="flex flex-row gap-2">
|
fileType={"energizer"}
|
||||||
<ForecastImport fileType={"pg"} name={"P&G"} />
|
name={"Energizer Forecast"}
|
||||||
</div>
|
/>
|
||||||
)}
|
</div>
|
||||||
{plantToken[0]?.value === "usksc1" && (
|
)}
|
||||||
<div className="flex flex-row gap-2">
|
{plantToken[0]?.value === "usflo1" && (
|
||||||
<ForecastImport fileType={"pg"} name={"P&G"} />
|
<div className="flex flex-row gap-2">
|
||||||
</div>
|
<ForecastImport fileType={"loreal"} name={"VMI Import"} />
|
||||||
)}
|
</div>
|
||||||
</div>
|
)}
|
||||||
);
|
{plantToken[0]?.value === "usstp1" && (
|
||||||
|
<div className="flex flex-row gap-2"></div>
|
||||||
|
)}
|
||||||
|
{plantToken[0]?.value === "usiow1" && (
|
||||||
|
<div className="flex flex-row gap-2">
|
||||||
|
<ForecastImport fileType={"pg"} name={"P&G"} />
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
{plantToken[0]?.value === "usiow2" && (
|
||||||
|
<div className="flex flex-row gap-2">
|
||||||
|
<ForecastImport fileType={"pg"} name={"P&G"} />
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
{plantToken[0]?.value === "usksc1" && (
|
||||||
|
<div className="flex flex-row gap-2">
|
||||||
|
<ForecastImport fileType={"pg"} name={"P&G"} />
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,70 +3,80 @@ import { useRef, useState } from "react";
|
|||||||
import { toast } from "sonner";
|
import { toast } from "sonner";
|
||||||
import { Button } from "@/components/ui/button";
|
import { Button } from "@/components/ui/button";
|
||||||
import { useAuth } from "@/lib/authClient";
|
import { useAuth } from "@/lib/authClient";
|
||||||
|
import { useNavigate, useRouterState } from "@tanstack/react-router";
|
||||||
|
|
||||||
export default function ForecastImport(props: any) {
|
export default function ForecastImport(props: any) {
|
||||||
const fileInputRef: any = useRef(null);
|
const fileInputRef: any = useRef(null);
|
||||||
const [posting, setPosting] = useState(false);
|
const [posting, setPosting] = useState(false);
|
||||||
//const token = localStorage.getItem("auth_token");
|
//const token = localStorage.getItem("auth_token");
|
||||||
const { session } = useAuth();
|
const { session } = useAuth();
|
||||||
//const [fileType, setFileType] = useState("");
|
//const [fileType, setFileType] = useState("");
|
||||||
const importOrders = async (e: any) => {
|
const navigate = useNavigate();
|
||||||
const file = e.target.files[0];
|
const router = useRouterState();
|
||||||
if (!file) {
|
const currentPath = router.location.href;
|
||||||
toast.error("Missing file please try again");
|
|
||||||
setPosting(false);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// create the form data with the correct fileType
|
const importOrders = async (e: any) => {
|
||||||
const formData = new FormData();
|
if (!session || !session.user) {
|
||||||
formData.append("postForecast", e.target.files[0]);
|
toast.error("You are allowed to do this unless you are logged in");
|
||||||
formData.append("fileType", props.fileType); // extra field
|
navigate({ to: "/login", search: { redirect: currentPath } });
|
||||||
formData.append("username", `${session?.user.username}`);
|
return;
|
||||||
|
}
|
||||||
|
const file = e.target.files[0];
|
||||||
|
if (!file) {
|
||||||
|
toast.error("Missing file please try again");
|
||||||
|
setPosting(false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// console.log(formData);
|
// create the form data with the correct fileType
|
||||||
toast.success("Import started.");
|
const formData = new FormData();
|
||||||
try {
|
formData.append("postForecast", e.target.files[0]);
|
||||||
const response = await axios.post(
|
formData.append("fileType", props.fileType); // extra field
|
||||||
"/lst/old/api/logistics/postforecastin",
|
formData.append("username", `${session?.user.username}`);
|
||||||
formData,
|
|
||||||
{
|
|
||||||
headers: {
|
|
||||||
"Content-Type": "multipart/form-data",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
);
|
|
||||||
//console.log("Upload successful:", response.data);
|
|
||||||
toast.success(response?.data?.message);
|
|
||||||
fileInputRef.current.value = null;
|
|
||||||
setPosting(false);
|
|
||||||
// toast.success(
|
|
||||||
// "File Uploaded, please validate processing in alplaprod 2.0"
|
|
||||||
// );
|
|
||||||
setPosting(false);
|
|
||||||
} catch (error) {
|
|
||||||
console.log(error);
|
|
||||||
toast.error("Upload failed");
|
|
||||||
}
|
|
||||||
setPosting(false);
|
|
||||||
};
|
|
||||||
|
|
||||||
const handleButtonClick = () => {
|
// console.log(formData);
|
||||||
setPosting(true);
|
toast.success("Import started.");
|
||||||
fileInputRef.current.click();
|
try {
|
||||||
};
|
const response = await axios.post(
|
||||||
return (
|
"/lst/old/api/logistics/postforecastin",
|
||||||
<div>
|
formData,
|
||||||
<Button onClick={handleButtonClick} disabled={posting}>
|
{
|
||||||
{props.name}
|
headers: {
|
||||||
</Button>
|
"Content-Type": "multipart/form-data",
|
||||||
<input
|
},
|
||||||
type="file"
|
}
|
||||||
accept=".xlsx, .xls, .xlsm"
|
);
|
||||||
ref={fileInputRef}
|
//console.log("Upload successful:", response.data);
|
||||||
style={{ display: "none" }}
|
toast.success(response?.data?.message);
|
||||||
onChange={importOrders}
|
fileInputRef.current.value = null;
|
||||||
/>
|
setPosting(false);
|
||||||
</div>
|
// toast.success(
|
||||||
);
|
// "File Uploaded, please validate processing in alplaprod 2.0"
|
||||||
|
// );
|
||||||
|
setPosting(false);
|
||||||
|
} catch (error) {
|
||||||
|
console.log(error);
|
||||||
|
toast.error("Upload failed");
|
||||||
|
}
|
||||||
|
setPosting(false);
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleButtonClick = () => {
|
||||||
|
setPosting(true);
|
||||||
|
fileInputRef.current.click();
|
||||||
|
};
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
<Button onClick={handleButtonClick} disabled={posting}>
|
||||||
|
{props.name}
|
||||||
|
</Button>
|
||||||
|
<input
|
||||||
|
type="file"
|
||||||
|
accept=".xlsx, .xls, .xlsm"
|
||||||
|
ref={fileInputRef}
|
||||||
|
style={{ display: "none" }}
|
||||||
|
onChange={importOrders}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,63 +3,72 @@ import { useRef, useState } from "react";
|
|||||||
import { toast } from "sonner";
|
import { toast } from "sonner";
|
||||||
import { Button } from "@/components/ui/button";
|
import { Button } from "@/components/ui/button";
|
||||||
import { useAuth } from "@/lib/authClient";
|
import { useAuth } from "@/lib/authClient";
|
||||||
|
import { useNavigate, useRouterState } from "@tanstack/react-router";
|
||||||
|
|
||||||
export default function OrderImport(props: any) {
|
export default function OrderImport(props: any) {
|
||||||
const fileInputRef: any = useRef(null);
|
const fileInputRef: any = useRef(null);
|
||||||
const [posting, setPosting] = useState(false);
|
const [posting, setPosting] = useState(false);
|
||||||
const { session } = useAuth();
|
const { session } = useAuth();
|
||||||
//const [fileType, setFileType] = useState("");
|
const navigate = useNavigate();
|
||||||
const importOrders = async (e: any) => {
|
const router = useRouterState();
|
||||||
const file = e.target.files[0];
|
const currentPath = router.location.href;
|
||||||
if (!file) {
|
//const [fileType, setFileType] = useState("");
|
||||||
toast.error("Missing file please try again");
|
const importOrders = async (e: any) => {
|
||||||
setPosting(false);
|
if (!session || !session.user) {
|
||||||
return;
|
toast.error("You are allowed to do this unless you are logged in");
|
||||||
}
|
navigate({ to: "/login", search: { redirect: currentPath } });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const file = e.target.files[0];
|
||||||
|
if (!file) {
|
||||||
|
toast.error("Missing file please try again");
|
||||||
|
setPosting(false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// create the form data with the correct fileType
|
// create the form data with the correct fileType
|
||||||
const formData = new FormData();
|
const formData = new FormData();
|
||||||
formData.append("postOrders", e.target.files[0]);
|
formData.append("postOrders", e.target.files[0]);
|
||||||
formData.append("fileType", props.fileType); // extra field
|
formData.append("fileType", props.fileType); // extra field
|
||||||
formData.append("username", `${session?.user.username}`);
|
formData.append("username", `${session?.user.username}`);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const response = await axios.post(
|
const response = await axios.post(
|
||||||
"/lst/old/api/logistics/postbulkorders",
|
"/lst/old/api/logistics/postbulkorders",
|
||||||
formData,
|
formData,
|
||||||
{
|
{
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "multipart/form-data",
|
"Content-Type": "multipart/form-data",
|
||||||
},
|
},
|
||||||
},
|
}
|
||||||
);
|
);
|
||||||
//console.log("Upload successful:", response.data);
|
//console.log("Upload successful:", response.data);
|
||||||
toast.success(response?.data?.message);
|
toast.success(response?.data?.message);
|
||||||
fileInputRef.current.value = null;
|
fileInputRef.current.value = null;
|
||||||
setPosting(false);
|
setPosting(false);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log(error);
|
console.log(error);
|
||||||
toast.error("Upload failed");
|
toast.error("Upload failed");
|
||||||
}
|
}
|
||||||
setPosting(false);
|
setPosting(false);
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleButtonClick = () => {
|
const handleButtonClick = () => {
|
||||||
setPosting(true);
|
setPosting(true);
|
||||||
fileInputRef.current.click();
|
fileInputRef.current.click();
|
||||||
};
|
};
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<Button onClick={handleButtonClick} disabled={posting}>
|
<Button onClick={handleButtonClick} disabled={posting}>
|
||||||
{props.name}
|
{props.name}
|
||||||
</Button>
|
</Button>
|
||||||
<input
|
<input
|
||||||
type="file"
|
type="file"
|
||||||
accept=".xlsx, .xls, .xlsm"
|
accept=".xlsx, .xls, .xlsm"
|
||||||
ref={fileInputRef}
|
ref={fileInputRef}
|
||||||
style={{ display: "none" }}
|
style={{ display: "none" }}
|
||||||
onChange={importOrders}
|
onChange={importOrders}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user