88 lines
2.8 KiB
TypeScript
88 lines
2.8 KiB
TypeScript
import { defineStore } from 'pinia';
|
|
import { ref } from 'vue';
|
|
import { api } from '@/plugins/axios';
|
|
import type { ConnectSimplexNotificationsPayload } from '@/types/shopSettings/ConnectSimplexNotificationsPayload';
|
|
import type { ShopSettings } from '@/types/shopSettings/ShopSettings';
|
|
import type { UpdateNotificationsPayload } from '@/types/shopSettings/UpdateNotificationsPayload';
|
|
import type { UpdateShippingNotePayload } from '@/types/shopSettings/UpdateShippingNotePayload';
|
|
import type { UpdateSimplexLinkPayload } from '@/types/shopSettings/UpdateSimplexLinkPayload';
|
|
|
|
export const useShopSettingsStore = defineStore('shopSettings', () => {
|
|
const settings = ref<ShopSettings | null>(null);
|
|
|
|
const fetchShopSettings = async (): Promise<ShopSettings> => {
|
|
const { data } = await api.get<ShopSettings>('/shop-settings');
|
|
|
|
settings.value = data;
|
|
|
|
return data;
|
|
};
|
|
|
|
const updateSimplexLink = async (payload: UpdateSimplexLinkPayload): Promise<ShopSettings> => {
|
|
const { data } = await api.patch<ShopSettings>('/shop-settings/simplex-link', payload);
|
|
|
|
settings.value = data;
|
|
|
|
return data;
|
|
};
|
|
|
|
const updateShippingNote = async (payload: UpdateShippingNotePayload): Promise<ShopSettings> => {
|
|
const { data } = await api.patch<ShopSettings>('/shop-settings/shipping-note', payload);
|
|
|
|
settings.value = data;
|
|
|
|
return data;
|
|
};
|
|
|
|
const updateNotifications = async (payload: UpdateNotificationsPayload): Promise<ShopSettings> => {
|
|
const { data } = await api.patch<ShopSettings>('/shop-settings/notifications', payload);
|
|
|
|
settings.value = data;
|
|
|
|
return data;
|
|
};
|
|
|
|
const connectSimplexNotifications = async (payload: ConnectSimplexNotificationsPayload): Promise<ShopSettings> => {
|
|
const { data } = await api.post<ShopSettings>('/shop-settings/simplex-connect', payload);
|
|
|
|
settings.value = data;
|
|
|
|
return data;
|
|
};
|
|
|
|
const uploadShopLogo = async (file: File): Promise<ShopSettings> => {
|
|
const formData = new FormData();
|
|
|
|
formData.append('file', file);
|
|
|
|
const { data } = await api.post<ShopSettings>('/shop-settings/logo', formData);
|
|
|
|
settings.value = data;
|
|
|
|
return data;
|
|
};
|
|
|
|
const uploadShopFavicon = async (file: File): Promise<ShopSettings> => {
|
|
const formData = new FormData();
|
|
|
|
formData.append('file', file);
|
|
|
|
const { data } = await api.post<ShopSettings>('/shop-settings/favicon', formData);
|
|
|
|
settings.value = data;
|
|
|
|
return data;
|
|
};
|
|
|
|
return {
|
|
settings,
|
|
fetchShopSettings,
|
|
updateSimplexLink,
|
|
updateShippingNote,
|
|
updateNotifications,
|
|
connectSimplexNotifications,
|
|
uploadShopLogo,
|
|
uploadShopFavicon
|
|
};
|
|
});
|