|
|
@@ -0,0 +1,198 @@
|
|
|
+import showAlert from "@/components/basic/Alert"
|
|
|
+import { View, Text } from "@tarojs/components";
|
|
|
+import './CheckAccess.scss'
|
|
|
+
|
|
|
+import { useContext, useEffect, useState } from "react";
|
|
|
+
|
|
|
+export default function CheckAccess() {
|
|
|
+ const [showFastAlert, setShowFastAlert] = useState(false)
|
|
|
+ const [alertTitle, setAlertTitle] = useState('')
|
|
|
+ const [alertContent, setAlertContent] = useState('')
|
|
|
+ const [showCancel, setShowCancel] = useState(false)
|
|
|
+ const [cancelText, setCancelText] = useState('')
|
|
|
+ const [confirmText, setConfirmText] = useState('')
|
|
|
+
|
|
|
+
|
|
|
+ useEffect(() => {
|
|
|
+ global.checkAccess = (acccessData: any) => {
|
|
|
+ const currentStatus = acccessData.current.qualification.status
|
|
|
+ const preStatus = acccessData.previous.qualification.status
|
|
|
+
|
|
|
+ if (preStatus == 'NOT_QUALIFIED' && currentStatus == 'NOT_QUALIFIED') {
|
|
|
+ const { streak_fast_current } = acccessData.current.qualification.condition
|
|
|
+
|
|
|
+ setShowFastAlert(true)
|
|
|
+ setAlertTitle('Well Done')
|
|
|
+ setAlertContent(`You're on a ${streak_fast_current}-day streak.
|
|
|
+ Two more days until unlocking 'Fasting with sleep.'`)
|
|
|
+ setShowCancel(false)
|
|
|
+ setConfirmText('Got it!')
|
|
|
+
|
|
|
+ // showAlert({
|
|
|
+ // title: 'Well Done',
|
|
|
+ // content: `You're on a ${streak_fast_current}-day streak.
|
|
|
+ // Two more days until unlocking 'Fasting with sleep.'`,
|
|
|
+ // showCancel: false,
|
|
|
+ // confirmText: 'Got it!',
|
|
|
+ // })
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ else if (preStatus == 'NOT_QUALIFIED' && currentStatus == 'PROVISIONAL_QUALIFIED') {
|
|
|
+
|
|
|
+ setShowFastAlert(true)
|
|
|
+ setAlertTitle('Premium Access Unlocked')
|
|
|
+ setAlertContent(`You've unlocked 'Fasting with Sleep' since you're on a x-day streak.`)
|
|
|
+ setShowCancel(true)
|
|
|
+ setCancelText('Stay with Fasting Only')
|
|
|
+ setConfirmText('Upgrade to Fasting with Sleep\n(Offer Expiring in 21:59:59)')
|
|
|
+
|
|
|
+ // showAlert({
|
|
|
+ // title: 'Premium Access Unlocked',
|
|
|
+ // content: `You've unlocked 'Fasting with Sleep' since you're on a x-day streak.
|
|
|
+ // Are you ready to up the game?`,
|
|
|
+ // showCancel: true,
|
|
|
+ // cancelText: 'Stay',
|
|
|
+ // confirmText: 'Upgrade',
|
|
|
+ // confirm: upgrade
|
|
|
+ // })
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ else if (preStatus == 'PROVISIONAL_QUALIFIED' && currentStatus == 'PROVISIONAL_QUALIFIED') {
|
|
|
+ const { streak_fast_current, streak_sleep_current } = acccessData.current.qualification.condition
|
|
|
+
|
|
|
+ setShowFastAlert(true)
|
|
|
+ setAlertTitle('Well Done')
|
|
|
+ setAlertContent(`You're on a ${streak_fast_current}-day fasting streak${streak_sleep_current > 0 ? ' and a ' + streak_sleep_current + '-day sleep streak' : ''}.\nKeep 'em going to stay in the game.'`)
|
|
|
+ setShowCancel(false)
|
|
|
+ setConfirmText('Got it!')
|
|
|
+ // showAlert({
|
|
|
+ // title: 'Well Done',
|
|
|
+ // content: `You're on a ${streak_fast_current}-day fasting streak${streak_sleep_current > 0 ? ' and a ' + streak_sleep_current + '-day sleep streak' : ''}.
|
|
|
+ // Keep 'em going to stay in the game.'`,
|
|
|
+ // showCancel: false,
|
|
|
+ // confirmText: 'Got it!',
|
|
|
+ // })
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ else if (preStatus == 'PROVISIONAL_QUALIFIED' && currentStatus == 'NOT_QUALIFIED') {
|
|
|
+ setShowFastAlert(true)
|
|
|
+ setAlertTitle('Premium Access Lost')
|
|
|
+ setAlertContent(`You've lost premium access to the 'Fasting with Sleep' feature
|
|
|
+ since you lost your fasting streak. To regain access, become a PRO or achieve a new 3-day fasting streak.`)
|
|
|
+ setShowCancel(true)
|
|
|
+ setCancelText('Achieve')
|
|
|
+ setConfirmText('Become')
|
|
|
+ // showAlert({
|
|
|
+ // title: 'Premium Access Lost',
|
|
|
+ // content: `You've lost premium access to the 'Fasting with Sleep' feature
|
|
|
+ // since you lost your fasting streak. To regain access, become a PRO or achieve a new 3-day fasting streak.`,
|
|
|
+ // showCancel: true,
|
|
|
+ // cancelText:'Achieve',
|
|
|
+ // confirmText: 'Become',
|
|
|
+ // })
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }, [])
|
|
|
+
|
|
|
+ function upgrade() {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ function confirm() {
|
|
|
+ setShowFastAlert(false)
|
|
|
+ }
|
|
|
+
|
|
|
+ function cancel() {
|
|
|
+ setShowFastAlert(false)
|
|
|
+ }
|
|
|
+
|
|
|
+ function alertPop() {
|
|
|
+ return <View className="fast_alert_container">
|
|
|
+ <View className="fast_alert_content">
|
|
|
+ <View className="fast_alert_title">{alertTitle}</View>
|
|
|
+ <View className="fast_alert_detail">{alertContent}</View>
|
|
|
+ <View className="fast_alert_confirm" onClick={confirm}>{confirmText}</View>
|
|
|
+ {
|
|
|
+ showCancel && <View className="fast_alert_cancel" onClick={cancel}>{cancelText}</View>
|
|
|
+ }
|
|
|
+
|
|
|
+ </View>
|
|
|
+ </View>
|
|
|
+ }
|
|
|
+
|
|
|
+ return <View>
|
|
|
+ {
|
|
|
+ showFastAlert && alertPop()
|
|
|
+ }
|
|
|
+ </View>
|
|
|
+}
|
|
|
+
|
|
|
+// export const checkAccessProvisional = (acccessData: any, showFastAlert: any) => {
|
|
|
+// debugger
|
|
|
+
|
|
|
+// const currentStatus = acccessData.current.qualification.status
|
|
|
+// const preStatus = acccessData.previous.qualification.status
|
|
|
+
|
|
|
+// function upgrade() {
|
|
|
+// showAlert({
|
|
|
+// title: 'Congrats on Your PRO Status!',
|
|
|
+// content: `To preserve this status, continue your fasting streak in 倒计时 and begin your sleep streak. Remember to keep both of them going.`,
|
|
|
+// showCancel: false,
|
|
|
+// confirmText: 'Got it!',
|
|
|
+// })
|
|
|
+// }
|
|
|
+
|
|
|
+// if (preStatus == 'NOT_QUALIFIED' && currentStatus == 'NOT_QUALIFIED') {
|
|
|
+// debugger
|
|
|
+// const { streak_fast_current } = acccessData.current.qualification.condition
|
|
|
+// showFastAlert({
|
|
|
+// title: 'hello world'
|
|
|
+// })
|
|
|
+// // showAlert({
|
|
|
+// // title: 'Well Done',
|
|
|
+// // content: `You're on a ${streak_fast_current}-day streak.
|
|
|
+// // Two more days until unlocking 'Fasting with sleep.'`,
|
|
|
+// // showCancel: false,
|
|
|
+// // confirmText: 'Got it!',
|
|
|
+// // })
|
|
|
+// return;
|
|
|
+// }
|
|
|
+// else if (preStatus == 'NOT_QUALIFIED' && currentStatus == 'PROVISIONAL_QUALIFIED') {
|
|
|
+// showAlert({
|
|
|
+// title: 'Premium Access Unlocked',
|
|
|
+// content: `You've unlocked 'Fasting with Sleep' since you're on a x-day streak.
|
|
|
+// Are you ready to up the game?`,
|
|
|
+// showCancel: true,
|
|
|
+// cancelText: 'Stay',
|
|
|
+// confirmText: 'Upgrade',
|
|
|
+// confirm: upgrade
|
|
|
+// })
|
|
|
+// return;
|
|
|
+// }
|
|
|
+// else if (preStatus == 'PROVISIONAL_QUALIFIED' && currentStatus == 'PROVISIONAL_QUALIFIED') {
|
|
|
+// const { streak_fast_current, streak_sleep_current } = acccessData.current.qualification.condition
|
|
|
+// showAlert({
|
|
|
+// title: 'Well Done',
|
|
|
+// content: `You're on a ${streak_fast_current}-day fasting streak${streak_sleep_current > 0 ? ' and a ' + streak_sleep_current + '-day sleep streak' : ''}.
|
|
|
+// Keep 'em going to stay in the game.'`,
|
|
|
+// showCancel: false,
|
|
|
+// confirmText: 'Got it!',
|
|
|
+// })
|
|
|
+// return;
|
|
|
+// }
|
|
|
+// else if (preStatus == 'PROVISIONAL_QUALIFIED' && currentStatus == 'NOT_QUALIFIED') {
|
|
|
+// showFastAlert({
|
|
|
+// title: 'hello world2'
|
|
|
+// })
|
|
|
+// // showAlert({
|
|
|
+// // title: 'Premium Access Lost',
|
|
|
+// // content: `You've lost premium access to the 'Fasting with Sleep' feature
|
|
|
+// // since you lost your fasting streak. To regain access, become a PRO or achieve a new 3-day fasting streak.`,
|
|
|
+// // showCancel: true,
|
|
|
+// // cancelText:'Achieve',
|
|
|
+// // confirmText: 'Become',
|
|
|
+// // })
|
|
|
+// return;
|
|
|
+// }
|
|
|
+// }
|