More.tsx 8.01 KB
import { useNavigate } from "react-router";
import { Card } from "../components/ui/card";
import {
  User,
  Printer,
  MapPin,
  RefreshCw,
  Languages,
  HelpCircle,
  LogOut,
  ChevronRight,
} from "lucide-react";
import {
  AlertDialog,
  AlertDialogAction,
  AlertDialogCancel,
  AlertDialogContent,
  AlertDialogDescription,
  AlertDialogFooter,
  AlertDialogHeader,
  AlertDialogTitle,
  AlertDialogTrigger,
} from "../components/ui/alert-dialog";
import { useLanguage } from "../contexts/LanguageContext";

export default function More() {
  const navigate = useNavigate();
  const { t } = useLanguage();
  const userName = localStorage.getItem("userName") || "Employee";

  const handleLogout = () => {
    localStorage.removeItem("isLoggedIn");
    localStorage.removeItem("userName");
    localStorage.removeItem("storeName");
    navigate("/login");
  };

  return (
    <div className="min-h-screen bg-gray-50">
      {/* Header */}
      <div className="bg-white border-b border-gray-200 p-6">
        <h1 className="text-2xl font-semibold text-gray-900 mb-1">{t("more.title")}</h1>
        <p className="text-base text-gray-600">{userName}</p>
      </div>

      {/* Menu Items */}
      <div className="p-6">
        <div className="space-y-2">
          <Card
            className="p-5 cursor-pointer hover:shadow-md transition-shadow"
            onClick={() => navigate("/more/profile")}
          >
            <div className="flex items-center gap-4">
              <div className="w-12 h-12 rounded-full bg-blue-100 flex items-center justify-center flex-shrink-0">
                <User className="w-6 h-6 text-blue-600" />
              </div>
              <div className="flex-1 min-w-0">
                <h3 className="text-base font-semibold text-gray-900">
                  {t("more.profile")}
                </h3>
                <p className="text-sm text-gray-600">
                  {t("more.profile.desc")}
                </p>
              </div>
              <ChevronRight className="w-5 h-5 text-gray-400 flex-shrink-0" />
            </div>
          </Card>

          <Card
            className="p-5 cursor-pointer hover:shadow-md transition-shadow"
            onClick={() => navigate("/more/printers")}
          >
            <div className="flex items-center gap-4">
              <div className="w-12 h-12 rounded-full bg-gray-100 flex items-center justify-center flex-shrink-0">
                <Printer className="w-6 h-6 text-gray-600" />
              </div>
              <div className="flex-1 min-w-0">
                <h3 className="text-base font-semibold text-gray-900">
                  {t("more.printers")}
                </h3>
                <p className="text-sm text-gray-600">
                  {t("more.printers.desc")}
                </p>
              </div>
              <ChevronRight className="w-5 h-5 text-gray-400 flex-shrink-0" />
            </div>
          </Card>

          <Card
            className="p-5 cursor-pointer hover:shadow-md transition-shadow"
            onClick={() => navigate("/more/location")}
          >
            <div className="flex items-center gap-4">
              <div className="w-12 h-12 rounded-full bg-gray-100 flex items-center justify-center flex-shrink-0">
                <MapPin className="w-6 h-6 text-gray-600" />
              </div>
              <div className="flex-1 min-w-0">
                <h3 className="text-base font-semibold text-gray-900">
                  {t("more.location")}
                </h3>
                <p className="text-sm text-gray-600">
                  {t("more.location.desc")}
                </p>
              </div>
              <ChevronRight className="w-5 h-5 text-gray-400 flex-shrink-0" />
            </div>
          </Card>

          <Card
            className="p-5 cursor-pointer hover:shadow-md transition-shadow"
            onClick={() => navigate("/more/sync")}
          >
            <div className="flex items-center gap-4">
              <div className="w-12 h-12 rounded-full bg-gray-100 flex items-center justify-center flex-shrink-0">
                <RefreshCw className="w-6 h-6 text-gray-600" />
              </div>
              <div className="flex-1 min-w-0">
                <h3 className="text-base font-semibold text-gray-900">
                  {t("more.sync")}
                </h3>
                <p className="text-sm text-gray-600">
                  {t("more.sync.desc")}
                </p>
              </div>
              <ChevronRight className="w-5 h-5 text-gray-400 flex-shrink-0" />
            </div>
          </Card>

          <Card
            className="p-5 cursor-pointer hover:shadow-md transition-shadow"
            onClick={() => navigate("/more/language")}
          >
            <div className="flex items-center gap-4">
              <div className="w-12 h-12 rounded-full bg-gray-100 flex items-center justify-center flex-shrink-0">
                <Languages className="w-6 h-6 text-gray-600" />
              </div>
              <div className="flex-1 min-w-0">
                <h3 className="text-base font-semibold text-gray-900">
                  {t("more.language")}
                </h3>
                <p className="text-sm text-gray-600">
                  {t("more.language.desc")}
                </p>
              </div>
              <ChevronRight className="w-5 h-5 text-gray-400 flex-shrink-0" />
            </div>
          </Card>

          <Card
            className="p-5 cursor-pointer hover:shadow-md transition-shadow"
            onClick={() => navigate("/more/support")}
          >
            <div className="flex items-center gap-4">
              <div className="w-12 h-12 rounded-full bg-gray-100 flex items-center justify-center flex-shrink-0">
                <HelpCircle className="w-6 h-6 text-gray-600" />
              </div>
              <div className="flex-1 min-w-0">
                <h3 className="text-base font-semibold text-gray-900">
                  {t("more.support")}
                </h3>
                <p className="text-sm text-gray-600">
                  {t("more.support.desc")}
                </p>
              </div>
              <ChevronRight className="w-5 h-5 text-gray-400 flex-shrink-0" />
            </div>
          </Card>

          {/* Logout */}
          <AlertDialog>
            <AlertDialogTrigger asChild>
              <Card className="p-4 cursor-pointer hover:shadow-md transition-shadow border-red-200">
                <div className="flex items-center gap-4">
                  <div className="p-2 bg-red-50 rounded-lg">
                    <LogOut className="w-6 h-6 text-red-600" />
                  </div>
                  <div className="flex-1">
                    <h3 className="text-base font-semibold text-red-600 mb-0.5">
                      {t("more.logout")}
                    </h3>
                    <p className="text-sm text-gray-500">Sign out of your account</p>
                  </div>
                  <ChevronRight className="w-5 h-5 text-gray-400" />
                </div>
              </Card>
            </AlertDialogTrigger>
            <AlertDialogContent>
              <AlertDialogHeader>
                <AlertDialogTitle>Confirm Logout</AlertDialogTitle>
                <AlertDialogDescription>
                  Are you sure you want to logout? Any unsaved changes will be lost.
                </AlertDialogDescription>
              </AlertDialogHeader>
              <AlertDialogFooter>
                <AlertDialogCancel>{t("common.cancel")}</AlertDialogCancel>
                <AlertDialogAction
                  onClick={handleLogout}
                  className="bg-red-600 hover:bg-red-700"
                >
                  {t("more.logout")}
                </AlertDialogAction>
              </AlertDialogFooter>
            </AlertDialogContent>
          </AlertDialog>
        </div>
      </div>

      {/* App Info */}
      <div className="p-6 text-center">
        <p className="text-sm text-gray-500 mb-1">Food Label System</p>
        <p className="text-sm text-gray-400">Version 1.0.0</p>
      </div>
    </div>
  );
}