mirror of
https://github.com/chillpadclub/bedolaga-cabinet.git
synced 2026-07-29 18:13:47 +00:00
Update Subscription.tsx
This commit is contained in:
@@ -21,6 +21,20 @@ const getErrorMessage = (error: unknown): string => {
|
|||||||
return 'Произошла ошибка'
|
return 'Произошла ошибка'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Helper to extract insufficient balance error details
|
||||||
|
const getInsufficientBalanceError = (error: unknown): { required: number; balance: number } | null => {
|
||||||
|
if (error instanceof AxiosError) {
|
||||||
|
const detail = error.response?.data?.detail
|
||||||
|
if (typeof detail === 'object' && detail?.code === 'insufficient_balance') {
|
||||||
|
return {
|
||||||
|
required: detail.required || 0,
|
||||||
|
balance: detail.balance || 0,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
// Icons
|
// Icons
|
||||||
const CopyIcon = () => (
|
const CopyIcon = () => (
|
||||||
<svg className="w-4 h-4" fill="none" viewBox="0 0 24 24" stroke="currentColor" strokeWidth={1.5}>
|
<svg className="w-4 h-4" fill="none" viewBox="0 0 24 24" stroke="currentColor" strokeWidth={1.5}>
|
||||||
@@ -742,11 +756,26 @@ export default function Subscription() {
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* Pause mutation error */}
|
{/* Pause mutation error */}
|
||||||
{pauseMutation.isError && (
|
{pauseMutation.isError && (() => {
|
||||||
<div className="mt-4 text-sm text-error-400 bg-error-500/10 px-4 py-3 rounded-lg text-center">
|
const balanceError = getInsufficientBalanceError(pauseMutation.error)
|
||||||
{getErrorMessage(pauseMutation.error)}
|
if (balanceError) {
|
||||||
</div>
|
const missingAmount = balanceError.required - balanceError.balance
|
||||||
)}
|
return (
|
||||||
|
<div className="mt-4">
|
||||||
|
<InsufficientBalancePrompt
|
||||||
|
missingAmountKopeks={missingAmount}
|
||||||
|
message={t('subscription.pause.insufficientBalance')}
|
||||||
|
compact
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
return (
|
||||||
|
<div className="mt-4 text-sm text-error-400 bg-error-500/10 px-4 py-3 rounded-lg text-center">
|
||||||
|
{getErrorMessage(pauseMutation.error)}
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
})()}
|
||||||
|
|
||||||
{/* Paused info or Next charge progress bar */}
|
{/* Paused info or Next charge progress bar */}
|
||||||
{subscription.is_daily_paused ? (
|
{subscription.is_daily_paused ? (
|
||||||
|
|||||||
Reference in New Issue
Block a user