refactor(mock): remove lib/mock fixtures and empty stores
This commit is contained in:
+4
-5
@@ -1,5 +1,4 @@
|
||||
import { generateId } from "@/lib/id"
|
||||
import { mockChatMessages, mockChatSessions, mockUsers } from "@/lib/mock"
|
||||
import type { ChatMessage, ChatSession, Order } from "@/lib/types"
|
||||
import { create } from "zustand"
|
||||
|
||||
@@ -11,8 +10,8 @@ interface ChatState {
|
||||
sendImageMessage: (sessionId: string, actorId: string, imageUrl: string) => void
|
||||
}
|
||||
|
||||
function resolveAvatar(userId: string) {
|
||||
return mockUsers.find((user) => user.id === userId)?.avatar ?? ""
|
||||
function resolveAvatar(_userId: string) {
|
||||
return ""
|
||||
}
|
||||
|
||||
function shouldReadonly(status: Order["status"]) {
|
||||
@@ -20,8 +19,8 @@ function shouldReadonly(status: Order["status"]) {
|
||||
}
|
||||
|
||||
export const useChatStore = create<ChatState>((set, get) => ({
|
||||
sessions: mockChatSessions,
|
||||
messages: mockChatMessages,
|
||||
sessions: [],
|
||||
messages: [],
|
||||
ensureOrderSession: (order) => {
|
||||
const existing = get().sessions.find(
|
||||
(session) => session.type === "order" && session.orderId === order.id,
|
||||
|
||||
+1
-2
@@ -1,5 +1,4 @@
|
||||
import { generateId } from "@/lib/id"
|
||||
import { mockComments } from "@/lib/mock"
|
||||
import type { Comment, User } from "@/lib/types"
|
||||
import { create } from "zustand"
|
||||
|
||||
@@ -10,7 +9,7 @@ interface CommentState {
|
||||
}
|
||||
|
||||
export const useCommentStore = create<CommentState>((set) => ({
|
||||
comments: mockComments,
|
||||
comments: [],
|
||||
addComment: (postId, author, content) => {
|
||||
const normalizedContent = content.trim()
|
||||
if (!normalizedContent) return null
|
||||
|
||||
+1
-37
@@ -3,7 +3,6 @@ import { DISPUTE_TO_RESOLVED_MS, DISPUTE_TO_REVIEWING_MS } from "@/lib/config/de
|
||||
import { allow, deny } from "@/lib/decision"
|
||||
import type { ApiDecision } from "@/lib/errors"
|
||||
import { generateId } from "@/lib/id"
|
||||
import { mockDisputes } from "@/lib/mock"
|
||||
import type { Dispute } from "@/lib/types"
|
||||
import { useAuthStore } from "@/store/auth"
|
||||
import { useNotificationStore } from "@/store/notifications"
|
||||
@@ -87,41 +86,6 @@ function resolveParticipantActor(orderId: string, userId: string): Actor | null
|
||||
return null
|
||||
}
|
||||
|
||||
function asRecord(dispute: Dispute): DisputeRecord {
|
||||
const timeline: DisputeTimelineItem[] = [
|
||||
{
|
||||
id: generateId("timeline"),
|
||||
type: "created",
|
||||
content: `${dispute.initiatorName} 提交争议`,
|
||||
createdAt: dispute.createdAt,
|
||||
},
|
||||
]
|
||||
|
||||
if (dispute.status === "reviewing") {
|
||||
timeline.push({
|
||||
id: generateId("timeline"),
|
||||
type: "reviewing",
|
||||
content: "平台已受理并进入审核",
|
||||
createdAt: dispute.createdAt,
|
||||
})
|
||||
}
|
||||
|
||||
if (dispute.status === "resolved") {
|
||||
timeline.push({
|
||||
id: generateId("timeline"),
|
||||
type: "resolved",
|
||||
content: "平台已给出仲裁结果",
|
||||
createdAt: dispute.createdAt,
|
||||
})
|
||||
}
|
||||
|
||||
return {
|
||||
...dispute,
|
||||
respondentEvidence: [],
|
||||
timeline,
|
||||
}
|
||||
}
|
||||
|
||||
function notifyDispute(orderId: string, title: string, content: string) {
|
||||
if (!useAuthStore.getState().notificationPrefs.order) {
|
||||
return
|
||||
@@ -200,7 +164,7 @@ export const useDisputeStore = create<DisputeState>((set, get) => {
|
||||
}
|
||||
|
||||
return {
|
||||
disputes: mockDisputes.map(asRecord),
|
||||
disputes: [],
|
||||
getDisputeByOrderId: (orderId) => get().disputes.find((dispute) => dispute.orderId === orderId),
|
||||
submitDispute: (input) => {
|
||||
const order = useOrderStore.getState().orders.find((item) => item.id === input.orderId)
|
||||
|
||||
+1
-2
@@ -1,5 +1,4 @@
|
||||
import { generateId } from "@/lib/id"
|
||||
import { mockFavorites } from "@/lib/mock"
|
||||
import type { Favorite } from "@/lib/types"
|
||||
import { create } from "zustand"
|
||||
|
||||
@@ -11,7 +10,7 @@ interface FavoriteState {
|
||||
}
|
||||
|
||||
export const useFavoriteStore = create<FavoriteState>((set, get) => ({
|
||||
favorites: mockFavorites,
|
||||
favorites: [],
|
||||
listFavoritesByUser: (userId) => get().favorites.filter((favorite) => favorite.userId === userId),
|
||||
isFavorited: (userId, targetType, targetId) =>
|
||||
get().favorites.some(
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import { generateId } from "@/lib/id"
|
||||
import { mockNotifications } from "@/lib/mock"
|
||||
import type { Notification } from "@/lib/types"
|
||||
import { create } from "zustand"
|
||||
|
||||
@@ -18,7 +17,7 @@ interface NotificationState {
|
||||
}
|
||||
|
||||
export const useNotificationStore = create<NotificationState>((set) => ({
|
||||
notifications: mockNotifications,
|
||||
notifications: [],
|
||||
addNotification: (input) => {
|
||||
const notification: Notification = {
|
||||
id: generateId("notif"),
|
||||
|
||||
+1
-2
@@ -8,7 +8,6 @@ import { allow, deny } from "@/lib/decision"
|
||||
import { evaluateOrderTransition, type OrderAction } from "@/lib/domain/order-machine"
|
||||
import type { ApiDecision } from "@/lib/errors"
|
||||
import { generateId } from "@/lib/id"
|
||||
import { mockOrders } from "@/lib/mock"
|
||||
import type { Order, OrderStatus } from "@/lib/types"
|
||||
import { useAuthStore } from "@/store/auth"
|
||||
import { useChatStore } from "@/store/chat"
|
||||
@@ -301,7 +300,7 @@ export const useOrderStore = create<OrderState>((set, get) => {
|
||||
}
|
||||
|
||||
return {
|
||||
orders: mockOrders,
|
||||
orders: [],
|
||||
createOrder: (input, actor) => {
|
||||
if (actor.role !== "consumer") {
|
||||
return { decision: deny(403, "仅客户可下单") }
|
||||
|
||||
+1
-2
@@ -1,4 +1,3 @@
|
||||
import { mockPlayers } from "@/lib/mock"
|
||||
import type { Player } from "@/lib/types"
|
||||
import { create } from "zustand"
|
||||
|
||||
@@ -9,7 +8,7 @@ interface PlayerState {
|
||||
}
|
||||
|
||||
export const usePlayerStore = create<PlayerState>((set) => ({
|
||||
players: mockPlayers,
|
||||
players: [],
|
||||
assignToShop: (playerId, shopId, shopName) =>
|
||||
set((state) => ({
|
||||
players: state.players.map((player) =>
|
||||
|
||||
+1
-2
@@ -1,5 +1,4 @@
|
||||
import { generateId } from "@/lib/id"
|
||||
import { mockPosts } from "@/lib/mock"
|
||||
import type { Post, User, UserRole } from "@/lib/types"
|
||||
import { create } from "zustand"
|
||||
|
||||
@@ -22,7 +21,7 @@ interface PostState {
|
||||
}
|
||||
|
||||
export const usePostStore = create<PostState>((set) => ({
|
||||
posts: mockPosts,
|
||||
posts: [],
|
||||
createPost: (input) => {
|
||||
const post: Post = {
|
||||
id: generateId("post"),
|
||||
|
||||
+2
-8
@@ -1,7 +1,6 @@
|
||||
import { allow, deny } from "@/lib/decision"
|
||||
import type { ApiDecision } from "@/lib/errors"
|
||||
import { generateId } from "@/lib/id"
|
||||
import { mockReviews, mockUsers } from "@/lib/mock"
|
||||
import type { Review } from "@/lib/types"
|
||||
import { useOrderStore } from "@/store/orders"
|
||||
import { create } from "zustand"
|
||||
@@ -20,10 +19,6 @@ interface ReviewState {
|
||||
hasUserReviewed: (orderId: string, userId: string) => boolean
|
||||
}
|
||||
|
||||
function resolveUser(userId: string) {
|
||||
return mockUsers.find((user) => user.id === userId)
|
||||
}
|
||||
|
||||
function resolveOrderUser(orderId: string, userId: string) {
|
||||
const order = useOrderStore.getState().orders.find((item) => item.id === orderId)
|
||||
if (!order) return null
|
||||
@@ -48,7 +43,7 @@ function resolveOrderUser(orderId: string, userId: string) {
|
||||
}
|
||||
|
||||
export const useReviewStore = create<ReviewState>((set, get) => ({
|
||||
reviews: mockReviews,
|
||||
reviews: [],
|
||||
getReviewsByOrder: (orderId) => get().reviews.filter((review) => review.orderId === orderId),
|
||||
hasUserReviewed: (orderId, userId) =>
|
||||
get().reviews.some((review) => review.orderId === orderId && review.fromUserId === userId),
|
||||
@@ -80,7 +75,6 @@ export const useReviewStore = create<ReviewState>((set, get) => ({
|
||||
return deny(400, "该订单已提交过评价")
|
||||
}
|
||||
|
||||
const fromUser = resolveUser(input.fromUserId)
|
||||
const createdAt = new Date().toISOString()
|
||||
|
||||
const review: Review = {
|
||||
@@ -88,7 +82,7 @@ export const useReviewStore = create<ReviewState>((set, get) => ({
|
||||
orderId: input.orderId,
|
||||
fromUserId: input.fromUserId,
|
||||
fromUserName: relation.fromUserName,
|
||||
fromUserAvatar: fromUser?.avatar ?? "",
|
||||
fromUserAvatar: "",
|
||||
toUserId: relation.toUserId,
|
||||
rating: input.rating,
|
||||
content: input.content?.trim() || undefined,
|
||||
|
||||
+1
-2
@@ -1,5 +1,4 @@
|
||||
import { generateId } from "@/lib/id"
|
||||
import { mockServices } from "@/lib/mock"
|
||||
import type { PlayerService } from "@/lib/types"
|
||||
import { create } from "zustand"
|
||||
|
||||
@@ -11,7 +10,7 @@ interface ServiceState {
|
||||
}
|
||||
|
||||
export const useServiceStore = create<ServiceState>((set) => ({
|
||||
services: mockServices,
|
||||
services: [],
|
||||
createService: (service) =>
|
||||
set((state) => ({
|
||||
services: [
|
||||
|
||||
+1
-2
@@ -1,4 +1,3 @@
|
||||
import { mockShops } from "@/lib/mock"
|
||||
import type { Shop, ShopSection } from "@/lib/types"
|
||||
import { create } from "zustand"
|
||||
|
||||
@@ -11,7 +10,7 @@ interface ShopState {
|
||||
}
|
||||
|
||||
export const useShopStore = create<ShopState>((set) => ({
|
||||
shops: mockShops,
|
||||
shops: [],
|
||||
updateShop: (shopId, patch) =>
|
||||
set((state) => ({
|
||||
shops: state.shops.map((shop) => (shop.id === shopId ? { ...shop, ...patch } : shop)),
|
||||
|
||||
+2
-3
@@ -1,6 +1,5 @@
|
||||
import { calculateOrderIncome } from "@/lib/domain/income"
|
||||
import { generateId } from "@/lib/id"
|
||||
import { mockTransactions, walletBalance } from "@/lib/mock"
|
||||
import type { WalletTransaction } from "@/lib/types"
|
||||
import { useShopStore } from "@/store/shops"
|
||||
import { create } from "zustand"
|
||||
@@ -17,8 +16,8 @@ interface WalletState {
|
||||
}
|
||||
|
||||
export const useWalletStore = create<WalletState>((set, get) => ({
|
||||
balance: walletBalance,
|
||||
transactions: mockTransactions,
|
||||
balance: 0,
|
||||
transactions: [],
|
||||
topUp: (amount) => {
|
||||
if (!Number.isFinite(amount) || amount <= 0) return
|
||||
const now = new Date().toISOString()
|
||||
|
||||
Reference in New Issue
Block a user