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 { 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);
|
//console.log(plantToken);
|
||||||
return (
|
return (
|
||||||
<div className="flex flex-row-reverse gap-1">
|
<div className="flex flex-row-reverse gap-1">
|
||||||
@@ -13,18 +14,36 @@ export default function DMButtons() {
|
|||||||
{/* dev and testserver sees all */}
|
{/* dev and testserver sees all */}
|
||||||
{testServers.includes(plantToken[0]?.value) && (
|
{testServers.includes(plantToken[0]?.value) && (
|
||||||
<div className="flex flex-row gap-2">
|
<div className="flex flex-row gap-2">
|
||||||
<OrderImport fileType={"abbott"} name={"Abbott truck list"} />
|
<OrderImport
|
||||||
<OrderImport fileType={"energizer"} name={"Energizer Truck List"} />
|
fileType={"abbott"}
|
||||||
|
name={"Abbott truck list"}
|
||||||
|
/>
|
||||||
|
<OrderImport
|
||||||
|
fileType={"energizer"}
|
||||||
|
name={"Energizer Truck List"}
|
||||||
|
/>
|
||||||
<ForecastImport fileType={"loreal"} name={"VMI Import"} />
|
<ForecastImport fileType={"loreal"} name={"VMI Import"} />
|
||||||
<ForecastImport fileType={"pg"} name={"P&G"} />
|
<ForecastImport fileType={"pg"} name={"P&G"} />
|
||||||
<ForecastImport fileType={"energizer"} name={"Energizer Forecast"} />
|
<ForecastImport
|
||||||
|
fileType={"energizer"}
|
||||||
|
name={"Energizer Forecast"}
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
{plantToken[0]?.value === "usday1" && (
|
{plantToken[0]?.value === "usday1" && (
|
||||||
<div className="flex flex-row gap-2">
|
<div className="flex flex-row gap-2">
|
||||||
<OrderImport fileType={"abbott"} name={"Abbott truck list"} />
|
<OrderImport
|
||||||
<OrderImport fileType={"energizer"} name={"Energizer Truck List"} />
|
fileType={"abbott"}
|
||||||
<ForecastImport fileType={"energizer"} name={"Energizer Forecast"} />
|
name={"Abbott truck list"}
|
||||||
|
/>
|
||||||
|
<OrderImport
|
||||||
|
fileType={"energizer"}
|
||||||
|
name={"Energizer Truck List"}
|
||||||
|
/>
|
||||||
|
<ForecastImport
|
||||||
|
fileType={"energizer"}
|
||||||
|
name={"Energizer Forecast"}
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
{plantToken[0]?.value === "usflo1" && (
|
{plantToken[0]?.value === "usflo1" && (
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ 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);
|
||||||
@@ -10,7 +11,16 @@ export default function ForecastImport(props: any) {
|
|||||||
//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 navigate = useNavigate();
|
||||||
|
const router = useRouterState();
|
||||||
|
const currentPath = router.location.href;
|
||||||
|
|
||||||
const importOrders = async (e: any) => {
|
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];
|
const file = e.target.files[0];
|
||||||
if (!file) {
|
if (!file) {
|
||||||
toast.error("Missing file please try again");
|
toast.error("Missing file please try again");
|
||||||
@@ -34,7 +44,7 @@ export default function ForecastImport(props: any) {
|
|||||||
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);
|
||||||
|
|||||||
@@ -3,13 +3,22 @@ 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 navigate = useNavigate();
|
||||||
|
const router = useRouterState();
|
||||||
|
const currentPath = router.location.href;
|
||||||
//const [fileType, setFileType] = useState("");
|
//const [fileType, setFileType] = useState("");
|
||||||
const importOrders = async (e: any) => {
|
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];
|
const file = e.target.files[0];
|
||||||
if (!file) {
|
if (!file) {
|
||||||
toast.error("Missing file please try again");
|
toast.error("Missing file please try again");
|
||||||
@@ -31,7 +40,7 @@ export default function OrderImport(props: any) {
|
|||||||
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);
|
||||||
|
|||||||
Reference in New Issue
Block a user