fix(dm): fixes to validate auth before submiting incase someone stays on the page to long
This commit is contained in:
@@ -6,6 +6,7 @@ export default function DMButtons() {
|
||||
const { settings } = useSettingStore();
|
||||
const testServers = ["test1", "test2", "test3"];
|
||||
const plantToken = settings.filter((n) => n.name === "plantToken");
|
||||
|
||||
//console.log(plantToken);
|
||||
return (
|
||||
<div className="flex flex-row-reverse gap-1">
|
||||
@@ -13,18 +14,36 @@ export default function DMButtons() {
|
||||
{/* dev and testserver sees all */}
|
||||
{testServers.includes(plantToken[0]?.value) && (
|
||||
<div className="flex flex-row gap-2">
|
||||
<OrderImport fileType={"abbott"} name={"Abbott truck list"} />
|
||||
<OrderImport fileType={"energizer"} name={"Energizer Truck List"} />
|
||||
<OrderImport
|
||||
fileType={"abbott"}
|
||||
name={"Abbott truck list"}
|
||||
/>
|
||||
<OrderImport
|
||||
fileType={"energizer"}
|
||||
name={"Energizer Truck List"}
|
||||
/>
|
||||
<ForecastImport fileType={"loreal"} name={"VMI Import"} />
|
||||
<ForecastImport fileType={"pg"} name={"P&G"} />
|
||||
<ForecastImport fileType={"energizer"} name={"Energizer Forecast"} />
|
||||
<ForecastImport
|
||||
fileType={"energizer"}
|
||||
name={"Energizer Forecast"}
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
{plantToken[0]?.value === "usday1" && (
|
||||
<div className="flex flex-row gap-2">
|
||||
<OrderImport fileType={"abbott"} name={"Abbott truck list"} />
|
||||
<OrderImport fileType={"energizer"} name={"Energizer Truck List"} />
|
||||
<ForecastImport fileType={"energizer"} name={"Energizer Forecast"} />
|
||||
<OrderImport
|
||||
fileType={"abbott"}
|
||||
name={"Abbott truck list"}
|
||||
/>
|
||||
<OrderImport
|
||||
fileType={"energizer"}
|
||||
name={"Energizer Truck List"}
|
||||
/>
|
||||
<ForecastImport
|
||||
fileType={"energizer"}
|
||||
name={"Energizer Forecast"}
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
{plantToken[0]?.value === "usflo1" && (
|
||||
|
||||
@@ -3,6 +3,7 @@ import { useRef, useState } from "react";
|
||||
import { toast } from "sonner";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { useAuth } from "@/lib/authClient";
|
||||
import { useNavigate, useRouterState } from "@tanstack/react-router";
|
||||
|
||||
export default function ForecastImport(props: any) {
|
||||
const fileInputRef: any = useRef(null);
|
||||
@@ -10,7 +11,16 @@ export default function ForecastImport(props: any) {
|
||||
//const token = localStorage.getItem("auth_token");
|
||||
const { session } = useAuth();
|
||||
//const [fileType, setFileType] = useState("");
|
||||
const navigate = useNavigate();
|
||||
const router = useRouterState();
|
||||
const currentPath = router.location.href;
|
||||
|
||||
const importOrders = async (e: any) => {
|
||||
if (!session || !session.user) {
|
||||
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");
|
||||
@@ -34,7 +44,7 @@ export default function ForecastImport(props: any) {
|
||||
headers: {
|
||||
"Content-Type": "multipart/form-data",
|
||||
},
|
||||
},
|
||||
}
|
||||
);
|
||||
//console.log("Upload successful:", response.data);
|
||||
toast.success(response?.data?.message);
|
||||
|
||||
@@ -3,13 +3,22 @@ import { useRef, useState } from "react";
|
||||
import { toast } from "sonner";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { useAuth } from "@/lib/authClient";
|
||||
import { useNavigate, useRouterState } from "@tanstack/react-router";
|
||||
|
||||
export default function OrderImport(props: any) {
|
||||
const fileInputRef: any = useRef(null);
|
||||
const [posting, setPosting] = useState(false);
|
||||
const { session } = useAuth();
|
||||
const navigate = useNavigate();
|
||||
const router = useRouterState();
|
||||
const currentPath = router.location.href;
|
||||
//const [fileType, setFileType] = useState("");
|
||||
const importOrders = async (e: any) => {
|
||||
if (!session || !session.user) {
|
||||
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");
|
||||
@@ -31,7 +40,7 @@ export default function OrderImport(props: any) {
|
||||
headers: {
|
||||
"Content-Type": "multipart/form-data",
|
||||
},
|
||||
},
|
||||
}
|
||||
);
|
||||
//console.log("Upload successful:", response.data);
|
||||
toast.success(response?.data?.message);
|
||||
|
||||
Reference in New Issue
Block a user