← marzneshin
/
dashboard/src/modules/settings/subscription/services/subscription-settings.mutate.ts
/
blame
https://dev.kronoz.win/r/marzneshin.git
dashboard/src/modules/settings/subscription/services/subscription-settings.mutate.ts
· v0.7.3
Source
| 1 | 78a3e64 | Dawsh | 2y ago | import { NodeType } from "@marzneshin/modules/nodes"; |
| 2 | 0178858 | Dawsh | 2y ago | import { useMutation } from "@tanstack/react-query"; |
| 3 | d636f3f | Dawsh | 2y ago | import { fetch, queryClient } from "@marzneshin/common/utils"; |
| 4 | 0178858 | Dawsh | 2y ago | import { toast } from "sonner"; |
| 5 | 0178858 | Dawsh | 2y ago | import i18n from "@marzneshin/features/i18n"; |
| 6 | 0178858 | Dawsh | 2y ago | import { |
| 7 | 0178858 | Dawsh | 2y ago | subscriptionSettingsQueryKey, |
| 8 | 0178858 | Dawsh | 2y ago | SubscriptionSettingsType |
| 9 | d636f3f | Dawsh | 2y ago | } from "@marzneshin/modules/settings/subscription"; |
| 10 | 0178858 | Dawsh | 2y ago | |
| 11 | 0178858 | Dawsh | 2y ago | export async function updateSubscriptionSettings(settings: SubscriptionSettingsType): Promise<NodeType> { |
| 12 | 0178858 | Dawsh | 2y ago | return fetch("/system/settings/subscription", { method: 'put', body: settings }).then((node) => { |
| 13 | 0178858 | Dawsh | 2y ago | return node; |
| 14 | 0178858 | Dawsh | 2y ago | }); |
| 15 | 0178858 | Dawsh | 2y ago | } |
| 16 | 0178858 | Dawsh | 2y ago | |
| 17 | 0178858 | Dawsh | 2y ago | const handleError = () => { |
| 18 | 0178858 | Dawsh | 2y ago | toast.error( |
| 19 | 0178858 | Dawsh | 2y ago | i18n.t('events.update.error'), |
| 20 | 0178858 | Dawsh | 2y ago | ) |
| 21 | 0178858 | Dawsh | 2y ago | } |
| 22 | 0178858 | Dawsh | 2y ago | |
| 23 | 0178858 | Dawsh | 2y ago | const handleSuccess = () => { |
| 24 | 0178858 | Dawsh | 2y ago | toast.success( |
| 25 | 0178858 | Dawsh | 2y ago | i18n.t('events.update.success.title', { name: "Subscription Settings" }), |
| 26 | 0178858 | Dawsh | 2y ago | { |
| 27 | 0178858 | Dawsh | 2y ago | description: i18n.t('events.update.success.desc') |
| 28 | 0178858 | Dawsh | 2y ago | }) |
| 29 | 89eec32 | Dawsh | 2y ago | queryClient.invalidateQueries({ queryKey: subscriptionSettingsQueryKey }) |
| 30 | 0178858 | Dawsh | 2y ago | } |
| 31 | 0178858 | Dawsh | 2y ago | |
| 32 | 0178858 | Dawsh | 2y ago | export const useSubscriptionSettingsMutation = () => { |
| 33 | 0178858 | Dawsh | 2y ago | return useMutation({ |
| 34 | 0178858 | Dawsh | 2y ago | mutationKey: subscriptionSettingsQueryKey, |
| 35 | 0178858 | Dawsh | 2y ago | mutationFn: updateSubscriptionSettings, |
| 36 | 0178858 | Dawsh | 2y ago | onError: handleError, |
| 37 | 0178858 | Dawsh | 2y ago | onSuccess: handleSuccess, |
| 38 | 0178858 | Dawsh | 2y ago | }) |
| 39 | 0178858 | Dawsh | 2y ago | } |