Files
api/web/store/purchase.ts
Zack Spear df168224ea refactor: webgui sync script to copy uui build (#1318)
- enhances `pnpm sync-webgui-repo` to include Unraid UI build + sync
options
- changed the dev intended ThemeSwitcher to use local / session storage

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

- **New Features**
- The theme switcher now respects your saved preferences, ensuring a
more personalized interface.
- The component build and synchronization process has been enhanced with
new options for UI components and clearer feedback during operations.
- New computed properties added for better state management in account
and purchase functionalities.

- **Bug Fixes**
- Improved error handling and logging during the component build
process.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
2025-04-03 09:17:21 -04:00

95 lines
2.2 KiB
TypeScript

import { defineStore, createPinia, setActivePinia } from 'pinia';
import { PURCHASE_CALLBACK } from '~/helpers/urls';
import { useCallbackActionsStore } from '~/store/callbackActions';
import { useServerStore } from '~/store/server';
/**
* @see https://stackoverflow.com/questions/73476371/using-pinia-with-vue-js-web-components
* @see https://github.com/vuejs/pinia/discussions/1085
*/
setActivePinia(createPinia());
export const usePurchaseStore = defineStore('purchase', () => {
const callbackStore = useCallbackActionsStore();
const serverStore = useServerStore();
const serverPurchasePayload = computed(() => serverStore.serverPurchasePayload);
const inIframe = computed(() => serverStore.inIframe);
const sendType = computed(() => callbackStore.sendType);
const activate = () => {
callbackStore.send(
PURCHASE_CALLBACK.toString(),
[{
server: {
...serverPurchasePayload.value,
},
type: 'activate',
}],
inIframe.value ? 'newTab' : undefined,
sendType.value,
);
};
const redeem = () => {
callbackStore.send(
PURCHASE_CALLBACK.toString(),
[{
server: {
...serverPurchasePayload.value,
},
type: 'redeem',
}],
inIframe.value ? 'newTab' : undefined,
sendType.value,
);
};
const purchase = () => {
callbackStore.send(
PURCHASE_CALLBACK.toString(),
[{
server: {
...serverPurchasePayload.value,
},
type: 'purchase',
}],
inIframe.value ? 'newTab' : undefined,
sendType.value,
);
};
const upgrade = () => {
callbackStore.send(
PURCHASE_CALLBACK.toString(),
[{
server: {
...serverPurchasePayload.value,
},
type: 'upgrade',
}],
inIframe.value ? 'newTab' : undefined,
sendType.value,
);
};
const renew = () => {
callbackStore.send(
PURCHASE_CALLBACK.toString(),
[{
server: {
...serverPurchasePayload.value,
},
type: 'renew',
}],
inIframe.value ? 'newTab' : undefined,
sendType.value,
);
};
return {
activate,
redeem,
purchase,
upgrade,
renew,
};
});