diff --git a/src/pages/repair/NotificationPreferences.tsx b/src/pages/repair/NotificationPreferences.tsx index aa7e89c..d6b426e 100644 --- a/src/pages/repair/NotificationPreferences.tsx +++ b/src/pages/repair/NotificationPreferences.tsx @@ -1,5 +1,14 @@ import { useEffect, useState } from "react" -import { Card, CardBody, CardHeader, Switch, Spinner, Button } from "@heroui/react" +import { + Modal, + ModalContent, + ModalHeader, + ModalBody, + ModalFooter, + Switch, + Spinner, + Button, +} from "@heroui/react" import { saturdayClient } from "../../utils/client" import type { components } from "../../types/saturday" @@ -11,15 +20,23 @@ interface NotificationPreferencesProps { } export default function NotificationPreferences({ token }: NotificationPreferencesProps) { + const [isOpen, setIsOpen] = useState(false) const [preferences, setPreferences] = useState([]) - const [isLoading, setIsLoading] = useState(true) + const [isLoading, setIsLoading] = useState(false) const [isSaving, setIsSaving] = useState(false) const [errorMessage, setErrorMessage] = useState("") const [successMessage, setSuccessMessage] = useState("") - useEffect(() => { + const openModal = () => { + setIsOpen(true) loadPreferences() - }, [token]) + } + + const closeModal = () => { + setIsOpen(false) + setErrorMessage("") + setSuccessMessage("") + } const loadPreferences = async () => { if (!token) return @@ -99,60 +116,73 @@ export default function NotificationPreferences({ token }: NotificationPreferenc } } - if (isLoading) { - return ( - - - - - - ) - } - return ( - - -

通知偏好设置

-

管理您希望接收的通知类型

-
- - {preferences.map((pref) => ( -
-
-

{pref.description}

-

{pref.notificationType}

-
- handleToggle(pref.notificationType, value)} - isDisabled={isSaving} - size="sm" - /> -
- ))} + <> + - {/* Messages */} - {errorMessage && ( -
-

{errorMessage}

-
- )} + + + +

通知偏好设置

+

管理您希望接收的通知类型

+
+ + {isLoading ? ( +
+ +
+ ) : ( + <> +
+ {preferences.map((pref) => ( +
+
+

{pref.description}

+

{pref.notificationType}

+
+ handleToggle(pref.notificationType, value)} + isDisabled={isSaving} + size="sm" + /> +
+ ))} - {successMessage && ( -
-

{successMessage}

-
- )} + {preferences.length === 0 && !errorMessage && ( +
+

暂无可用的通知偏好设置

+
+ )} +
- {preferences.length === 0 && !errorMessage && ( -
-

暂无可用的通知偏好设置

-
- )} -
-
+ {/* Messages */} + {errorMessage && ( +
+

{errorMessage}

+
+ )} + + {successMessage && ( +
+

{successMessage}

+
+ )} + + )} + + + + + + + ) } diff --git a/src/pages/repair/RepairAdmin.tsx b/src/pages/repair/RepairAdmin.tsx index 1d50ff5..eb70090 100644 --- a/src/pages/repair/RepairAdmin.tsx +++ b/src/pages/repair/RepairAdmin.tsx @@ -526,20 +526,13 @@ export default function App() {
维修管理
- { - userInfo?.roles?.find(v => v.toLowerCase() == "repair admin") - ?
- : <> - } -
- - {/* Notification Preferences Section */} - {token && ( -
- +
+ {token && } + {userInfo?.roles?.find(v => v.toLowerCase() == "repair admin") && ( + + )}
- )} - +
{/* Mobile Cards Layout */}