HEX
Server: LiteSpeed
System: Linux premium69.web-hosting.com 4.18.0-553.44.1.lve.el8.x86_64 #1 SMP Thu Mar 13 14:29:12 UTC 2025 x86_64
User: swifizcd (1555)
PHP: 8.2.30
Disabled: NONE
Upload Files
File: //home/swifizcd/buyease.com.ng/wp-content/plugins/extendify/src/Shared/state/site-profile.js
import apiFetch from '@wordpress/api-fetch';
import { create } from 'zustand';
import { createJSONStorage, devtools, persist } from 'zustand/middleware';

const { siteProfile } = window.extSharedData;

const state = (set) => ({
	siteProfile,
	setSiteProfile(data) {
		set((state) => {
			const updatedProfile = {
				...state.siteProfile,
				...data,
			};
			return { siteProfile: updatedProfile };
		});
	},
	resetState() {
		set({ siteProfile });
	},
});

const path = '/extendify/v1/shared/site-profile';
const storage = {
	getItem: async () => await apiFetch({ path }),
	setItem: async (_name, state) => {
		await apiFetch({
			path,
			method: 'POST',
			data: { siteProfile: JSON.stringify(state) },
		});
	},
};

export const useSiteProfileStore = create(
	persist(devtools(state, { name: 'Extendify Site Profile' }), {
		storage: createJSONStorage(() => storage),
		skipHydration: false,
	}),
	state,
);