|
|
@@ -10,6 +10,7 @@ import { chooseMode, initTarget, updateStep } from "@/store/set_target";
|
|
|
import { jumpPage } from "../hooks/Common";
|
|
|
import { useDidShow } from "@tarojs/taro";
|
|
|
import Taro from "@tarojs/taro";
|
|
|
+import { useTranslation } from "react-i18next";
|
|
|
|
|
|
let confirmAction: any = null;
|
|
|
let cancelAction: any = null;
|
|
|
@@ -32,6 +33,8 @@ export default function CheckAccess(props: { record: any, count: number }) {
|
|
|
const [confirmText, setConfirmText] = useState('')
|
|
|
const [subConfirmText, setSubConfirmText] = useState('')
|
|
|
|
|
|
+ const { t } = useTranslation()
|
|
|
+
|
|
|
//判断选择混合场景,如果成功了,就弹窗
|
|
|
const [checkChooseMixed, setCheckChooseMixed] = useState(false)
|
|
|
const [chooseMixedSuccess, setChooseMixedSuccess] = useState(false)
|
|
|
@@ -54,11 +57,11 @@ export default function CheckAccess(props: { record: any, count: number }) {
|
|
|
const currentStatus = obj.access.current.qualification.status
|
|
|
const preStatus = obj.access.previous.qualification.status
|
|
|
if (preStatus == 'PROVISIONAL_QUALIFIED' && currentStatus == 'NOT_QUALIFIED' && obj.current_record.status == 'WAIT_FOR_START') {
|
|
|
- lose()
|
|
|
+ lose(obj.access.current.qualification.condition)
|
|
|
}
|
|
|
- else if (currentStatus == 'PROVISIONAL_QUALIFIED'){
|
|
|
+ else if (currentStatus == 'PROVISIONAL_QUALIFIED') {
|
|
|
Taro.setStorage({ key: 'showedDisqualifiedAlert', data: false })
|
|
|
- if (new Date().getTime() > obj.access.current.qualification.expire && obj.current_record.status == 'WAIT_FOR_START'){
|
|
|
+ if (new Date().getTime() > obj.access.current.qualification.expire && obj.current_record.status == 'WAIT_FOR_START') {
|
|
|
if (global.indexPageRefresh) {
|
|
|
global.indexPageRefresh()
|
|
|
}
|
|
|
@@ -115,17 +118,21 @@ export default function CheckAccess(props: { record: any, count: number }) {
|
|
|
// setAccess(acccessData)
|
|
|
|
|
|
if (preStatus == 'NOT_QUALIFIED' && currentStatus == 'NOT_QUALIFIED') {
|
|
|
- const { streak_fast_current } = acccessData.current.qualification.condition
|
|
|
+ const { streak_fast_current, streak_required } = acccessData.current.qualification.condition
|
|
|
if (streak_fast_current == 0) {
|
|
|
return;
|
|
|
}
|
|
|
setShowFastAlert(true)
|
|
|
setKeepContent(false)
|
|
|
- setAlertTitle('Well Done')
|
|
|
- setAlertContent(`You're on a ${streak_fast_current}-day streak.
|
|
|
- ${streak_fast_current == 1 ? 'Two more days' : 'One more day'} until unlocking 'Fasting with sleep.'`)
|
|
|
+ setAlertTitle(t('feature.check_access.non_access.title'))
|
|
|
+ setAlertContent(t('feature.check_access.non_access.desc',
|
|
|
+ {
|
|
|
+ day: streak_fast_current,
|
|
|
+ left_day: streak_required - streak_fast_current,
|
|
|
+ day_unit: streak_required - streak_fast_current == 1 ? 'day' : 'days'
|
|
|
+ }))
|
|
|
setShowCancel(false)
|
|
|
- setConfirmText('Got it!')
|
|
|
+ setConfirmText(t('feature.check_access.non_access.btn'))
|
|
|
}
|
|
|
else if (preStatus == 'NOT_QUALIFIED' && currentStatus == 'PROVISIONAL_QUALIFIED') {
|
|
|
const { streak_fast_current } = acccessData.current.qualification.condition
|
|
|
@@ -134,12 +141,12 @@ export default function CheckAccess(props: { record: any, count: number }) {
|
|
|
const { expire } = acccessData.current.qualification
|
|
|
setShowFastAlert(true)
|
|
|
setKeepContent(false)
|
|
|
- setAlertTitle('Premium Access Unlocked')
|
|
|
- setAlertContent(`You've unlocked 'Fasting with Sleep' since you're on a ${streak_fast_current}-day streak.\nAre you ready to up the game?`)
|
|
|
+ setAlertTitle(t('feature.check_access.gain_access.title'))
|
|
|
+ setAlertContent(t('feature.check_access.gain_access.desc', { day: streak_fast_current }))
|
|
|
setShowCancel(true)
|
|
|
- setCancelText('Stay with Fasting Only')
|
|
|
- setConfirmText(`Upgrade to Fasting with Sleep`)
|
|
|
- setSubConfirmText(`Offer Expiring in ${TimeFormatter.countdown(expire)}`)
|
|
|
+ setCancelText(t('feature.check_access.gain_access.stay_btn'))
|
|
|
+ setConfirmText(t('feature.check_access.gain_access.upgrade'))
|
|
|
+ setSubConfirmText(t('feature.check_access.gain_access.upgrade_desc', { time: TimeFormatter.countdown(expire) }))
|
|
|
|
|
|
confirmAction = upgrade
|
|
|
timer = setInterval(() => {
|
|
|
@@ -157,13 +164,12 @@ export default function CheckAccess(props: { record: any, count: number }) {
|
|
|
const { expire } = acccessData.current.qualification
|
|
|
setShowFastAlert(true)
|
|
|
setKeepContent(false)
|
|
|
- setAlertTitle('Premium Access Unlocked')
|
|
|
- setAlertContent(`You've unlocked 'Fasting with Sleep' since you're on a ${streak_fast_current}-day streak.
|
|
|
- \nAre you ready to up the game?`)
|
|
|
+ setAlertTitle(t('feature.check_access.gain_access.title'))
|
|
|
+ setAlertContent(t('feature.check_access.gain_access.desc', { day: streak_fast_current }))
|
|
|
setShowCancel(true)
|
|
|
- setConfirmText(`Upgrade to Fasting with Sleep`)
|
|
|
- setSubConfirmText(`Offer Expiring in ${TimeFormatter.countdown(expire)}`)
|
|
|
- setCancelText('Stay with Fasting Only')
|
|
|
+ setCancelText(t('feature.check_access.gain_access.stay_btn'))
|
|
|
+ setConfirmText(t('feature.check_access.gain_access.upgrade'))
|
|
|
+ setSubConfirmText(t('feature.check_access.gain_access.upgrade_desc', { time: TimeFormatter.countdown(expire) }))
|
|
|
confirmAction = upgrade
|
|
|
timer = setInterval(() => {
|
|
|
if (new Date().getTime() > expire) {
|
|
|
@@ -177,14 +183,14 @@ export default function CheckAccess(props: { record: any, count: number }) {
|
|
|
}
|
|
|
|
|
|
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.`)
|
|
|
+ setAlertTitle(t('feature.check_access.stay_qualified.title'))
|
|
|
+ setAlertContent(t('feature.check_access.stay_qualified.title', { fast_streak_day: streak_fast_current, sleep_streak_day: streak_sleep_current }))
|
|
|
setShowCancel(false)
|
|
|
- setConfirmText('Got it!')
|
|
|
+ setConfirmText(t('feature.check_access.stay_qualified.btn'))
|
|
|
}
|
|
|
else if (preStatus == 'PROVISIONAL_QUALIFIED' && currentStatus == 'NOT_QUALIFIED') {
|
|
|
debugger
|
|
|
- lose();
|
|
|
+ lose(acccessData.current.qualification);
|
|
|
// setShowFastAlert(true)
|
|
|
// setAlertTitle('Premium Access Lost')
|
|
|
// setAlertContent(`You've lost premium access to the 'Fasting with Sleep' feature
|
|
|
@@ -200,32 +206,41 @@ export default function CheckAccess(props: { record: any, count: number }) {
|
|
|
const { expire } = access.current.qualification
|
|
|
setShowFastAlert(true)
|
|
|
setKeepContent(false)
|
|
|
- setAlertTitle('Congrats on Your PRO Status!')
|
|
|
- setAlertContent(`To preserve this status, continue your fasting streak in ${TimeFormatter.countdown(expire)} and begin your sleep streak. Remember to keep both of them going.`)
|
|
|
+ setAlertTitle(t('feature.check_access.upgrade_pro.title'))
|
|
|
+ setAlertContent(t('feature.check_access.upgrade_pro.desc', { time: TimeFormatter.countdown(expire) }))
|
|
|
setShowCancel(false)
|
|
|
- setConfirmText(`I got this!`)
|
|
|
+ setConfirmText(t('feature.check_access.upgrade_pro.btn'))
|
|
|
setSubConfirmText('')
|
|
|
timer = setInterval(() => {
|
|
|
|
|
|
if (new Date().getTime() > expire) {
|
|
|
- debugger
|
|
|
cancel()
|
|
|
return
|
|
|
}
|
|
|
- setAlertContent(`To preserve this status, continue your fasting streak in ${TimeFormatter.countdown(expire)} and begin your sleep streak. Remember to keep both of them going.`)
|
|
|
+ setAlertContent(t('feature.check_access.upgrade_pro.desc', { time: TimeFormatter.countdown(expire) }))
|
|
|
}, 1000)
|
|
|
}
|
|
|
|
|
|
- async function lose() {
|
|
|
- var showDayRing = await getStorage('showedDisqualifiedAlert') || false;
|
|
|
- if (showDayRing) {
|
|
|
+ async function lose(condition) {
|
|
|
+ var showedDisqualifiedAlert = await getStorage('showedDisqualifiedAlert') || false;
|
|
|
+ if (showedDisqualifiedAlert) {
|
|
|
return;
|
|
|
}
|
|
|
+
|
|
|
+ var type = ''
|
|
|
+ if (condition.streak_fast_current == 0 && condition.streak_sleep_current == 0) {
|
|
|
+ type = 'fasting and sleep'
|
|
|
+ }
|
|
|
+ else if (condition.streak_fast_current == 0) {
|
|
|
+ type = 'fasting'
|
|
|
+ }
|
|
|
+ else if (condition.streak_sleep_current == 0) {
|
|
|
+ type = 'sleep'
|
|
|
+ }
|
|
|
setShowFastAlert(true)
|
|
|
setKeepContent(false)
|
|
|
- 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.`)
|
|
|
+ setAlertTitle(t('feature.check_access.lose_access.title'))
|
|
|
+ setAlertContent(t('feature.check_access.lose_access.desc', { type: type }))
|
|
|
setShowCancel(true)
|
|
|
setCancelText('Achieve New Fasting Streak')
|
|
|
setConfirmText('Become a PRO member')
|
|
|
@@ -239,6 +254,7 @@ export default function CheckAccess(props: { record: any, count: number }) {
|
|
|
const { start_time, end_time } = global.ring.schedule.fast
|
|
|
var params: any = {
|
|
|
scenario: 'FAST',
|
|
|
+ trigger: 'POPUP_DISQUALIFIED_DISMISS',
|
|
|
schedule: {
|
|
|
fast: {
|
|
|
start_time: start_time,
|
|
|
@@ -267,12 +283,12 @@ export default function CheckAccess(props: { record: any, count: number }) {
|
|
|
if (prev_input && valid) {
|
|
|
setShowFastAlert(true)
|
|
|
setKeepContent(true)
|
|
|
- setAlertTitle('Update Sleep Schedule')
|
|
|
- setAlertContent(`Your sleep schedule was ${start_time} - ${end_time}.
|
|
|
- Do you want to update to a new schedule?`)
|
|
|
+ setAlertTitle(t('feature.check_access.sleep_schedule.title'))
|
|
|
+ setAlertContent(t('feature.check_access.sleep_schedule.desc',
|
|
|
+ { start_time: start_time, end_time: end_time }))
|
|
|
setShowCancel(true)
|
|
|
- setCancelText('Keep old schedule')
|
|
|
- setConfirmText('Update new shedule')
|
|
|
+ setCancelText(t('feature.check_access.sleep_schedule.cancel'))
|
|
|
+ setConfirmText(t('feature.check_access.sleep_schedule.confirm'))
|
|
|
setSubConfirmText('')
|
|
|
setTimeout(() => {
|
|
|
cancelAction = cancelSetting
|
|
|
@@ -299,7 +315,7 @@ export default function CheckAccess(props: { record: any, count: number }) {
|
|
|
}
|
|
|
|
|
|
function goSetting() {
|
|
|
-
|
|
|
+
|
|
|
getPlans().then(res => {
|
|
|
const data = res as { scenarios: any[] };
|
|
|
console.log(data)
|
|
|
@@ -320,7 +336,12 @@ export default function CheckAccess(props: { record: any, count: number }) {
|
|
|
dispatch(updateStep({ step: 2 }))
|
|
|
dispatch(chooseMode({ isMixed: true }))
|
|
|
setCheckChooseMixed(true)
|
|
|
- jumpPage(`/pages/clock/SetGoal?upgrade=true&isSelf=1`, 'SetGoal', navigation, {})
|
|
|
+ jumpPage(`/pages/clock/SetGoal?upgrade=true&isSelf=1&trigger_event=POPUP_QUALIFIED_UPGRADED_SET`, 'SetGoal', navigation, {
|
|
|
+ upgrade: true,
|
|
|
+ isSelf: 1,
|
|
|
+ trigger_event: 'POPUP_QUALIFIED_UPGRADED_SET'
|
|
|
+
|
|
|
+ })
|
|
|
confirmAction = goSetting
|
|
|
})
|
|
|
|
|
|
@@ -330,7 +351,7 @@ export default function CheckAccess(props: { record: any, count: number }) {
|
|
|
const { start_time, end_time } = global.ring.schedule.fast
|
|
|
var params: any = {
|
|
|
scenario: 'FAST_SLEEP',
|
|
|
- trigger_event:'PROVISIONAL_UPGRADE_KEEP',
|
|
|
+ trigger_event: 'POPUP_QUALIFIED_UPGRADED_DISMISS',
|
|
|
schedule: {
|
|
|
fast: {
|
|
|
start_time: start_time,
|
|
|
@@ -353,7 +374,7 @@ export default function CheckAccess(props: { record: any, count: number }) {
|
|
|
function confirm() {
|
|
|
if (!keepContent) {
|
|
|
setShowFastAlert(false)
|
|
|
-
|
|
|
+
|
|
|
}
|
|
|
|
|
|
if (timer) {
|