123456789101112131415161718192021222324252627282930313233343536373839404142434445 |
- import Taro, { useRouter } from "@tarojs/taro";
- import { useState } from "react";
- import { useAgentStore } from "@/store/agentStore";
- import { TAgentDetail } from "@/types/agent";
- const useEditContactCard = (
- editKey: string,
- initValue?: string,
- _agent?: TAgentDetail
- ) => {
- const router = useRouter();
- const { agentId } = router.params;
- const agent = useAgentStore((state) => _agent ?? state.agent);
- const agentContactCard = useAgentStore((state) => state.agentContactCard);
- const [value, setValue] = useState(initValue ?? "");
- const { editAgentCard,fetchAgent } = useAgentStore();
- const handleSubmit = async () => {
- if (!agent?.agentId) {
- return;
- }
- if (value.length <= 0) {
- return;
- }
- const result = await editAgentCard(agent.agentId, {
- ...agentContactCard,
- [editKey]: value,
- });
- if(result){
- await fetchAgent(agent.agentId)
- Taro.navigateBack()
- }
- };
- const onChange = (e: any) => {
- setValue(e);
- };
- return {
- value,
- setValue,
- onChange,
- handleSubmit,
- };
- };
- export default useEditContactCard;
|