FPSMS-frontend
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.
 
 

67 rindas
1.8 KiB

  1. "use client";
  2. import { useState, ReactNode, useEffect } from "react";
  3. import { Box, Tabs, Tab } from "@mui/material";
  4. import { useTranslation } from "react-i18next";
  5. import { useSearchParams, useRouter } from "next/navigation";
  6. interface WarehouseTabsProps {
  7. tab0Content: ReactNode;
  8. tab1Content: ReactNode;
  9. }
  10. function TabPanel({
  11. children,
  12. value,
  13. index,
  14. }: {
  15. children?: ReactNode;
  16. value: number;
  17. index: number;
  18. }) {
  19. return (
  20. <div role="tabpanel" hidden={value !== index}>
  21. {value === index && <Box sx={{ py: 3 }}>{children}</Box>}
  22. </div>
  23. );
  24. }
  25. export default function WarehouseTabs({ tab0Content, tab1Content }: WarehouseTabsProps) {
  26. const { t } = useTranslation("warehouse");
  27. const searchParams = useSearchParams();
  28. const router = useRouter();
  29. const [currentTab, setCurrentTab] = useState(() => {
  30. const tab = searchParams.get("tab");
  31. return tab === "1" ? 1 : 0;
  32. });
  33. useEffect(() => {
  34. const tab = searchParams.get("tab");
  35. setCurrentTab(tab === "1" ? 1 : 0);
  36. }, [searchParams]);
  37. const handleTabChange = (_e: React.SyntheticEvent, newValue: number) => {
  38. setCurrentTab(newValue);
  39. const params = new URLSearchParams(searchParams.toString());
  40. if (newValue === 0) params.delete("tab");
  41. else params.set("tab", String(newValue));
  42. router.push(`?${params.toString()}`, { scroll: false });
  43. };
  44. return (
  45. <Box sx={{ width: "100%" }}>
  46. <Box sx={{ borderBottom: 1, borderColor: "divider" }}>
  47. <Tabs value={currentTab} onChange={handleTabChange}>
  48. <Tab label={t("Warehouse List")} />
  49. <Tab label={t("Stock Take Section & Warehouse Mapping")} />
  50. </Tabs>
  51. </Box>
  52. <TabPanel value={currentTab} index={0}>
  53. {tab0Content}
  54. </TabPanel>
  55. <TabPanel value={currentTab} index={1}>
  56. {tab1Content}
  57. </TabPanel>
  58. </Box>
  59. );
  60. }