mirror of
https://github.com/QuantumNous/new-api.git
synced 2026-09-06 17:46:23 +00:00
feat: require compliance confirmation for paid features
Gate payment, redemption, subscription, and invitation reward flows behind an audited compliance acknowledgement.
This commit is contained in:
@@ -18,8 +18,14 @@ For commercial licensing, please contact support@quantumnous.com
|
||||
*/
|
||||
import React, { useState } from 'react'
|
||||
import useDialogState from '@/hooks/use-dialog'
|
||||
import {
|
||||
getOptionValue,
|
||||
useSystemOptions,
|
||||
} from '@/features/system-settings/hooks/use-system-options'
|
||||
import { type PlanRecord, type SubscriptionsDialogType } from '../types'
|
||||
|
||||
const CURRENT_COMPLIANCE_TERMS_VERSION = 'v1'
|
||||
|
||||
type SubscriptionsContextType = {
|
||||
open: SubscriptionsDialogType | null
|
||||
setOpen: (str: SubscriptionsDialogType | null) => void
|
||||
@@ -27,6 +33,7 @@ type SubscriptionsContextType = {
|
||||
setCurrentRow: React.Dispatch<React.SetStateAction<PlanRecord | null>>
|
||||
refreshTrigger: number
|
||||
triggerRefresh: () => void
|
||||
complianceConfirmed: boolean
|
||||
}
|
||||
|
||||
const SubscriptionsContext =
|
||||
@@ -40,6 +47,15 @@ export function SubscriptionsProvider({
|
||||
const [open, setOpen] = useDialogState<SubscriptionsDialogType>(null)
|
||||
const [currentRow, setCurrentRow] = useState<PlanRecord | null>(null)
|
||||
const [refreshTrigger, setRefreshTrigger] = useState(0)
|
||||
const { data } = useSystemOptions()
|
||||
const complianceOptions = getOptionValue(data?.data, {
|
||||
'payment_setting.compliance_confirmed': false,
|
||||
'payment_setting.compliance_terms_version': '',
|
||||
})
|
||||
const complianceConfirmed =
|
||||
complianceOptions['payment_setting.compliance_confirmed'] &&
|
||||
complianceOptions['payment_setting.compliance_terms_version'] ===
|
||||
CURRENT_COMPLIANCE_TERMS_VERSION
|
||||
|
||||
const triggerRefresh = () => setRefreshTrigger((prev) => prev + 1)
|
||||
|
||||
@@ -52,6 +68,7 @@ export function SubscriptionsProvider({
|
||||
setCurrentRow,
|
||||
refreshTrigger,
|
||||
triggerRefresh,
|
||||
complianceConfirmed,
|
||||
}}
|
||||
>
|
||||
{children}
|
||||
|
||||
Reference in New Issue
Block a user