refactor(react-hooks): enable stricter effect rules
Turn on react-hooks/set-state-in-effect and react-hooks/incompatible-library, then remove effect-driven local state sync patterns across affected pages. Keep behavior stable by deriving values from source state, remounting tab state by role key, and replacing useForm watch with useWatch.
This commit is contained in:
@@ -10,7 +10,7 @@ import {
|
||||
XCircle,
|
||||
} from "lucide-react"
|
||||
import Link from "next/link"
|
||||
import { useEffect, useState } from "react"
|
||||
import { useEffect } from "react"
|
||||
import { Button } from "@/components/ui/button"
|
||||
import { notifySuccess } from "@/lib/toast"
|
||||
import type { OrderStatus } from "@/lib/types"
|
||||
@@ -37,26 +37,23 @@ export default function OrderActions({
|
||||
}: OrderActionsProps) {
|
||||
const order = useOrderStore((state) => state.orders.find((item) => item.id === orderId))
|
||||
const updateOrderStatus = useOrderStore((state) => state.updateOrderStatus)
|
||||
const sessions = useChatStore((state) => state.sessions)
|
||||
const ensureOrderSession = useChatStore((state) => state.ensureOrderSession)
|
||||
const dispatchMode = useShopStore((state) => {
|
||||
if (!order?.shopId) return "manual"
|
||||
const shop = state.shops.find((item) => item.id === order.shopId)
|
||||
return shop?.dispatchMode ?? "manual"
|
||||
})
|
||||
const [resolvedChatSessionId, setResolvedChatSessionId] = useState(chatSessionId)
|
||||
const resolvedChatSessionId =
|
||||
chatSessionId ??
|
||||
sessions.find((session) => session.type === "order" && session.orderId === orderId)?.id
|
||||
|
||||
const status = order?.status ?? initialStatus
|
||||
|
||||
useEffect(() => {
|
||||
if (chatSessionId) {
|
||||
setResolvedChatSessionId(chatSessionId)
|
||||
return
|
||||
}
|
||||
|
||||
if (!order) return
|
||||
const session = ensureOrderSession(order)
|
||||
setResolvedChatSessionId(session.id)
|
||||
}, [chatSessionId, order, ensureOrderSession])
|
||||
if (chatSessionId || !order || resolvedChatSessionId) return
|
||||
ensureOrderSession(order)
|
||||
}, [chatSessionId, order, ensureOrderSession, resolvedChatSessionId])
|
||||
|
||||
useEffect(() => {
|
||||
if (!order) return
|
||||
|
||||
Reference in New Issue
Block a user