Guest User

Untitled

a guest
May 22nd, 2024
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import { useTranslations, useLocale } from "next-intl";
  2. import {
  3.   useRouter,
  4.   usePathname,
  5.   pathnames,
  6.   getPathname,
  7. } from "@/src/navigation";
  8.  
  9. interface JobSeekerSidebarProps {}
  10.  
  11. const JobSeekerSidebar: React.FC<JobSeekerSidebarProps> = () => {
  12.   const router = useRouter();
  13.   const pathname = usePathname();
  14.   const t = useTranslations("sidebar");
  15.   const locale = useLocale() as "en" | "ro"; // Casting locale to the expected type
  16.  
  17.   const handleButtonClick = (
  18.     path: keyof typeof pathnames,
  19.     params?: { [key: string]: string }
  20.   ) => {
  21.     // Get the localized path based on the current locale
  22.     let localizedPath = getPathname({
  23.       locale,
  24.       href: path,
  25.     });
  26.  
  27.     // If params are provided, replace the placeholders in the path
  28.     if (params) {
  29.       localizedPath = Object.keys(params).reduce((acc, key) => {
  30.         return acc.replace(`:${key}`, params[key]);
  31.       }, localizedPath);
  32.     }
  33.  
  34.     console.log(localizedPath);
  35.     // Navigate to the constructed path
  36.     router.push(localizedPath);
  37.   };
  38.  
  39.   return (
  40.     <div
  41.       style={{
  42.         boxSizing: "border-box",
  43.         display: "flex",
  44.         flexDirection: "column",
  45.         height: "100%",
  46.       }}
  47.     >
  48.       <div
  49.         style={{
  50.           height: "38px",
  51.           backgroundColor: "var(--background)",
  52.           border: "0.1px solid var(--border)",
  53.           borderTopLeftRadius: "8px",
  54.           borderTopRightRadius: "8px",
  55.           padding: "2px 14px 0",
  56.           display: "flex",
  57.           alignItems: "center",
  58.           justifyContent: "flex-start",
  59.         }}
  60.       >
  61.         <p style={{ fontWeight: "300", fontSize: "14px", color: "#646363" }}>
  62.           {t("myDashboard")}
  63.         </p>
  64.       </div>
  65.       <div
  66.         style={{
  67.           backgroundColor: "var(--foreground)",
  68.           border: "0.1px solid var(--border)",
  69.           borderBottomLeftRadius: "8px",
  70.           borderBottomRightRadius: "8px",
  71.           borderTop: "none",
  72.           padding: "14px",
  73.           flexGrow: 1,
  74.           maxHeight: "100%",
  75.           overflow: "auto",
  76.         }}
  77.       >
  78.         <div style={{ display: "flex", flexDirection: "column", gap: "20px" }}>
  79.           <button
  80.             onClick={() => handleButtonClick("/user/hello", { id: "bruh" })}
  81.           >
  82.             Navigate
  83.           </button>
  84.         </div>
  85.       </div>
  86.     </div>
  87.   );
  88. };
  89.  
  90. export default JobSeekerSidebar;
  91.  
Advertisement
Add Comment
Please, Sign In to add comment