|
@@ -1,61 +1,113 @@
|
|
|
-import { create } from 'zustand'
|
|
|
-import {
|
|
|
- bluebookAiAgent,
|
|
|
-} from '@/xiaolanbenlib/api/index'
|
|
|
-import request from '@/xiaolanbenlib/module/axios.js'
|
|
|
+import { create } from "zustand";
|
|
|
+import { bluebookAiAgent } from "@/xiaolanbenlib/api/index";
|
|
|
+import request from "@/xiaolanbenlib/module/axios.js";
|
|
|
|
|
|
-import { createAgent as _createAgent, deleteAgent as _deleteAgent } from "@/service/agent";
|
|
|
-import { TAgentDetail, TAgent } from '@/types/agent'
|
|
|
+import {
|
|
|
+ createAgent as _createAgent,
|
|
|
+ deleteAgent as _deleteAgent,
|
|
|
+ editAgentCard as _editAgentCard,
|
|
|
+ editAgentCharacter as _editAgentCharacter,
|
|
|
+} from "@/service/agent";
|
|
|
+import { TAgentDetail, TAgent, TAgentContactCard, TEditAgentCharacter } from "@/types/agent";
|
|
|
|
|
|
export interface AgentStoreState {
|
|
|
- agents: TAgent[]
|
|
|
- agent: TAgentDetail | null
|
|
|
- fetchAgents: () => Promise<TAgent[]>
|
|
|
- fetchAgent: (agentId: string) => Promise<TAgentDetail | null>
|
|
|
- createAgent: (data: TAgentDetail) => Promise<TAgentDetail | null>
|
|
|
+ agents: TAgent[];
|
|
|
+ agent: TAgentDetail | null;
|
|
|
+ agentCard: TAgentContactCard | null;
|
|
|
+ fetchAgents: () => Promise<TAgent[]>;
|
|
|
+ fetchAgent: (agentId: string) => Promise<TAgentDetail | null>;
|
|
|
+ createAgent: (data: TAgentDetail) => Promise<TAgentDetail | null>;
|
|
|
+ editAgentCharacter: (agentId: string, data: TEditAgentCharacter) => Promise<void>;
|
|
|
+ editAgentCard: (
|
|
|
+ agentId: string,
|
|
|
+ data: TAgentContactCard
|
|
|
+ ) => Promise<TAgentContactCard | null>;
|
|
|
// deleteAgent: (agentId: string) => Promise<void>
|
|
|
}
|
|
|
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
export const useAgentStore = create<AgentStoreState>((set, get) => ({
|
|
|
agents: [],
|
|
|
agent: null,
|
|
|
+ agentCard: null,
|
|
|
fetchAgents: async () => {
|
|
|
- const response = await request.get<TAgent[]>(`${bluebookAiAgent}api/v1/my/agents`)
|
|
|
- if(response && response?.data?.length){
|
|
|
- set({ agents: response.data })
|
|
|
- return response.data
|
|
|
+ const response = await request.get<TAgent[]>(
|
|
|
+ `${bluebookAiAgent}api/v1/my/agents`
|
|
|
+ );
|
|
|
+ if (response && response?.data?.length) {
|
|
|
+ set({ agents: response.data });
|
|
|
+ return response.data;
|
|
|
}
|
|
|
-
|
|
|
- return []
|
|
|
+
|
|
|
+ return [];
|
|
|
},
|
|
|
fetchAgent: async (agentId: string) => {
|
|
|
- const response = await request.get<TAgentDetail>(`${bluebookAiAgent}api/v1/my/agent/${agentId}`)
|
|
|
- if(response.data){
|
|
|
- set({ agent: response.data})
|
|
|
- return response.data
|
|
|
+ const response = await request.get<TAgentDetail>(
|
|
|
+ `${bluebookAiAgent}api/v1/my/agent/${agentId}`
|
|
|
+ );
|
|
|
+ if (response.data) {
|
|
|
+ const agent = response.data;
|
|
|
+ set({
|
|
|
+ agent: response.data,
|
|
|
+ agentCard: {
|
|
|
+ address: agent.address ?? "",
|
|
|
+ email: agent.email ?? "",
|
|
|
+ entName: agent.entName ?? "",
|
|
|
+ mobile: agent.mobile ?? "",
|
|
|
+ name: agent.name ?? "",
|
|
|
+ position: agent.position ?? "",
|
|
|
+ qrCodeUrl: agent.qrCodeUrl ?? "",
|
|
|
+ },
|
|
|
+ });
|
|
|
+
|
|
|
+ return response.data;
|
|
|
}
|
|
|
- return null
|
|
|
+ return null;
|
|
|
},
|
|
|
- createAgent: async (data: TAgentDetail) => {
|
|
|
- const newAgent = await request.post(`${bluebookAiAgent}api/v1/my/agent`, data) as TAgentDetail
|
|
|
- if(newAgent){
|
|
|
+ createAgent: async () => {
|
|
|
+ const response = await _createAgent();
|
|
|
+ if (response.data) {
|
|
|
set((state) => {
|
|
|
return {
|
|
|
- agents: [...state.agents, {
|
|
|
- "agentId": newAgent.agentId ?? '',
|
|
|
- "isDefault": newAgent.isDefault ?? false,
|
|
|
- "isEnt": newAgent.isEnt ?? false,
|
|
|
- "isNewEnt": newAgent.isNewEnt ?? false,
|
|
|
- "name": newAgent.name ?? ''
|
|
|
- }]
|
|
|
- }
|
|
|
- })
|
|
|
- return newAgent
|
|
|
+ agents: [
|
|
|
+ ...state.agents,
|
|
|
+ {
|
|
|
+ agentId: response.data.agentId ?? "",
|
|
|
+ isDefault: response.data.isDefault ?? false,
|
|
|
+ isEnt: response.data.isEnt ?? false,
|
|
|
+ isNewEnt: response.data.isNewEnt ?? false,
|
|
|
+ name: response.data.name ?? "",
|
|
|
+ },
|
|
|
+ ],
|
|
|
+ };
|
|
|
+ });
|
|
|
+ return response.data;
|
|
|
}
|
|
|
- return null
|
|
|
+ return null;
|
|
|
+ },
|
|
|
+ editAgentCharacter: async (agentId: string, data: TEditAgentCharacter) => {
|
|
|
+ const response = await _editAgentCharacter(agentId, data);
|
|
|
+ console.log(response.data);
|
|
|
+
|
|
|
+ },
|
|
|
+ editAgentCard: async (agentId: string, data: TAgentContactCard) => {
|
|
|
+ const response = await _editAgentCard(agentId, data);
|
|
|
+ console.log(response.data);
|
|
|
+ if (response) {
|
|
|
+ // set((state) => {
|
|
|
+ // return {
|
|
|
+ // agents: [...state.agents, {
|
|
|
+ // "agentId": newAgent.agentId ?? '',
|
|
|
+ // "isDefault": newAgent.isDefault ?? false,
|
|
|
+ // "isEnt": newAgent.isEnt ?? false,
|
|
|
+ // "isNewEnt": newAgent.isNewEnt ?? false,
|
|
|
+ // "name": newAgent.name ?? ''
|
|
|
+ // }]
|
|
|
+ // }
|
|
|
+ // })
|
|
|
+ // return newAgent
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ return null;
|
|
|
},
|
|
|
// deleteAgent: async (agentId: string)=> {
|
|
|
// const response = await _deleteAgent(agentId)
|
|
@@ -68,7 +120,4 @@ export const useAgentStore = create<AgentStoreState>((set, get) => ({
|
|
|
// })
|
|
|
// }
|
|
|
// }
|
|
|
-}))
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
+}));
|