You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Global-sales/src/stores/CustomerRelationStore.js

42 lines
1.0 KiB
JavaScript

import { create } from 'zustand'
import { devtools } from 'zustand/middleware'
import { fetchJSON, postForm } from '@/utils/request'
import { HT3, EMAIL_HOST } from '@/config'
import { isNotEmpty, prepareUrl } from '@/utils/commons'
export const useCustomerRelationStore = create((set, get) => ({
loading: false,
setLoading: (loading) => set({ loading }),
tasksList: [],
fetchSearchTasks: async (data) => {
set({ loading: true })
const formData = new FormData()
for (const key in data) {
formData.append(key, data[key])
}
fetch(`${HT3}/customerrelation/search_tasks`, {
method: 'POST',
body: formData,
})
.then((res) => {
if (!res.ok) {
throw new Error(`HTTP error! status: ${res.status}`)
}
return res.json()
})
.then((data) => {
set({ tasksList: data })
})
.catch((error) => {
console.error('Fetch error:', error)
})
.finally(() => {
set({ loading: false })
})
},
}))
export default useCustomerRelationStore