@@ -13,11 +13,12 @@ function makeModalInstance(set: Set, get: Get, key: string) {
store: {},
setState(state, store) {
const modals = get().modals;
+ const currentModal = modals[key];
- store = store ?? {};
+ const newStore = store !== undefined ? store : (currentModal?.store ?? {});
set(() => ({
- modals: { ...modals, [this.id]: { ...modals[key], state, store } },
+ modals: { ...modals, [this.id]: { ...modals[key], state, store: newStore } },
}));
},
setStoreProperty(key, value) {
@@ -63,7 +63,7 @@ export const SubscriptionChangeNotificationPlate = () => {
- Подтвердить смену тарифа
+ {tokensToAdd != null && fromTokens === toTokens ? 'Подтвердить' : 'Подтвердить смену тарифа'}
Отмена
@@ -42,23 +42,26 @@ export const accountApi = {
return null
}
- try {
- const { data } = await axios.post>(
- API_URL + '/payments/plans',
- {
- uid: plan,
- is_test: 1,
+ const response = await axios.post>(
+ API_URL + '/payments/plans',
+ {
+ uid: plan,
+ is_test: 1,
+ },
+ {
+ headers: {
+ Authorization: `Bearer ${token}`,
},
- {
- headers: {
- Authorization: `Bearer ${token}`,
- },
- }
- )
- return data.payment_url
- } catch (err) {
- return null
+ }
+ )
+
+ if (response.status >= 400) {
+ const error = new Error('Payment failed') as Error & { response: { data: unknown } }
+ error.response = { data: response.data }
+ throw error
}
+
+ return response.data.payment_url
},
async changePassword(
@@ -5,6 +5,7 @@ import { useSession } from 'next-auth/react'
import { useAppSelector } from '#/app/store/store'
import { balanceSelector } from '#/shared/lib/selectors'
+import { useShowDataStore } from '#/shared/lib/hooks/use-show-data'
import LightningSvg from '#/assets/svg/lightning.svg?react'
import { getModalById, SUBSCRIPTION_CHANGE_NOTIFICATION } from '#/features/modals'
import { accountApi } from '#/shared/api/account-endpoints'
@@ -24,6 +25,7 @@ const Offer: React.FC = ({ uid, tokens_per_plan, price, grouped_fea
const { data } = useSession()
const isRecurring = useAppSelector((state) => state.user.payment_plan?.is_recurring) ?? false
const balance = useAppSelector(balanceSelector)
+ const { showMessage } = useShowDataStore()
const unitMap: Record = {
Изображения: 'изображений',
@@ -60,8 +62,14 @@ const Offer: React.FC = ({ uid, tokens_per_plan, price, grouped_fea
const modal = getModalById(SUBSCRIPTION_CHANGE_NOTIFICATION)
const pay = async (planUid: string) => {
- const urlForPay = await accountApi.payProduct(data!.access, planUid)
- urlForPay ? await Router.push(urlForPay) : null
+ try {
+ const urlForPay = await accountApi.payProduct(data!.access, planUid)
+ urlForPay ? await Router.push(urlForPay) : null
+ } catch (err: any) {
+ const detail = err?.response?.data?.detail
+ const message = detail ?? 'Произошла ошибка при оплате';
+ showMessage(message)
+ }
}
const isFreePlan = currentPlanTokens <= 10