Improve hall chat retries, meetup-live lifecycle, home/mine remote-config UX, and add isolated social/API regression tests without deploying. Co-authored-by: Cursor <cursoragent@cursor.com>
180 lines
5.4 KiB
TypeScript
180 lines
5.4 KiB
TypeScript
import { useEffect, useRef, useState } from 'react'
|
||
import { Input } from '@tarojs/components'
|
||
import Taro from '@tarojs/taro'
|
||
import { H5El } from './H5El'
|
||
import {
|
||
fetchSocialJoinStatus,
|
||
paySocialJoin,
|
||
} from '@/utils/socialJoinPay'
|
||
import './JoinPaySheet.scss'
|
||
|
||
const EMAIL_RE = /^[^\s@]+@[^\s@]+\.[^\s@]+$/
|
||
const EMAIL_KEY = 'userEmail'
|
||
|
||
type Props = {
|
||
open: boolean
|
||
onClose: () => void
|
||
onPaid?: () => void
|
||
}
|
||
|
||
/**
|
||
* 加群收费底栏 — 微信虚拟支付(social-join),不是 VIP / community。
|
||
* rem + 全宽底栏,避免 designWidth:750 缩水。
|
||
*/
|
||
export function JoinPaySheet({ open, onClose, onPaid }: Props) {
|
||
const [email, setEmail] = useState('')
|
||
const [busy, setBusy] = useState(false)
|
||
const [err, setErr] = useState('')
|
||
const [priceLabel, setPriceLabel] = useState('¥49')
|
||
const [already, setAlready] = useState(false)
|
||
const [checking, setChecking] = useState(true)
|
||
const [enabled, setEnabled] = useState(false)
|
||
const submitLock = useRef(false)
|
||
|
||
useEffect(() => {
|
||
if (!open) return
|
||
try {
|
||
setEmail(String(Taro.getStorageSync(EMAIL_KEY) || ''))
|
||
} catch {
|
||
setEmail('')
|
||
}
|
||
setErr('')
|
||
let cancelled = false
|
||
setChecking(true)
|
||
setEnabled(false)
|
||
setBusy(false)
|
||
setAlready(false)
|
||
void fetchSocialJoinStatus().then((s) => {
|
||
if (cancelled) return
|
||
setChecking(false)
|
||
if (!s?.ok) { setErr('暂时无法确认价格与资格,请重新打开后重试'); return }
|
||
setAlready(s.isMember)
|
||
setEnabled(s.enabled)
|
||
if (!s.enabled && !s.isMember) setErr('暂未开放加群支付')
|
||
setPriceLabel(`¥${(s.priceFen / 100).toFixed(2).replace(/\.00$/, '')}`)
|
||
})
|
||
return () => { cancelled = true }
|
||
}, [open])
|
||
|
||
if (!open) return null
|
||
|
||
const submit = async () => {
|
||
if (submitLock.current || checking || !enabled) return
|
||
if (already) {
|
||
onClose()
|
||
return
|
||
}
|
||
const value = email.trim().toLowerCase()
|
||
if (!EMAIL_RE.test(value)) {
|
||
setErr('请输入有效邮箱')
|
||
return
|
||
}
|
||
setErr('')
|
||
submitLock.current = true
|
||
setBusy(true)
|
||
try {
|
||
Taro.setStorageSync(EMAIL_KEY, value)
|
||
Taro.setStorageSync('userName', value.split('@')[0] || '游民')
|
||
await paySocialJoin()
|
||
setAlready(true)
|
||
Taro.showToast({ title: '已加入游民社区', icon: 'success' })
|
||
onPaid?.()
|
||
onClose()
|
||
} catch (e) {
|
||
const msg = String((e as Error)?.message || e || '')
|
||
if (/取消|cancel/i.test(msg)) {
|
||
setErr('')
|
||
} else {
|
||
setErr(msg || '支付唤起失败,请稍后重试')
|
||
}
|
||
} finally {
|
||
submitLock.current = false
|
||
setBusy(false)
|
||
}
|
||
}
|
||
|
||
return (
|
||
<H5El className='social-join-sheet-mask' onClick={() => !busy && onClose()}>
|
||
<H5El
|
||
className='social-join-sheet-panel'
|
||
role='dialog' aria-modal='true' aria-label='加入社区'
|
||
onClick={(e) => {
|
||
e?.stopPropagation?.()
|
||
}}
|
||
>
|
||
<H5El className='social-join-sheet-handle' aria-hidden />
|
||
<H5El className='social-join-sheet-head'>
|
||
<H5El as='span' className='social-join-brand'>
|
||
✨ 游民社区 · 加群
|
||
</H5El>
|
||
<H5El
|
||
as='button'
|
||
type='button'
|
||
className='social-join-sheet-close'
|
||
aria-label='关闭'
|
||
disabled={busy}
|
||
onClick={() => !busy && onClose()}
|
||
>
|
||
✕
|
||
</H5El>
|
||
</H5El>
|
||
|
||
<H5El as='h2' className='social-join-sheet-title'>
|
||
{already ? '你已在群里' : '加入游民社区'}
|
||
</H5El>
|
||
<H5El as='p' className='social-muted social-join-sheet-lead'>
|
||
{already
|
||
? '认识同频 · 开视频 · 找搭子,直接去逛就好。'
|
||
: `认识同频的人 · 开视频聊聊 · 出来见一面 · 一起做点事`}
|
||
</H5El>
|
||
|
||
{!already ? (
|
||
<>
|
||
<H5El className='social-join-price' aria-label='加群费用'>
|
||
<H5El as='strong'>{priceLabel}</H5El>
|
||
<H5El as='span'>一次性加群 · 非 VIP 会员</H5El>
|
||
</H5El>
|
||
<H5El className='social-join-field'>
|
||
<H5El as='span'>邮箱</H5El>
|
||
<Input
|
||
className='social-join-input'
|
||
type='text'
|
||
placeholder='你的常用邮箱'
|
||
value={email}
|
||
disabled={busy}
|
||
onInput={(e) => setEmail(e.detail.value)}
|
||
/>
|
||
</H5El>
|
||
{err ? (
|
||
<H5El as='p' className='social-join-err' role='alert'>
|
||
{err}
|
||
</H5El>
|
||
) : null}
|
||
<H5El
|
||
as='button'
|
||
type='button'
|
||
className='btn btn-primary social-join-sheet-submit'
|
||
disabled={busy || checking || !enabled} loading={busy || checking}
|
||
onClick={() => void submit()}
|
||
>
|
||
{checking ? '正在确认…' : busy ? '正在唤起支付…' : `确认并支付 ${priceLabel}`}
|
||
</H5El>
|
||
<H5El as='p' className='social-join-privacy'>
|
||
🔒 邮箱用于账号识别 · 微信小程序虚拟支付
|
||
</H5El>
|
||
</>
|
||
) : (
|
||
<H5El
|
||
as='button'
|
||
type='button'
|
||
className='btn btn-primary social-join-sheet-submit'
|
||
onClick={onClose}
|
||
>
|
||
好的,继续逛
|
||
</H5El>
|
||
)}
|
||
</H5El>
|
||
</H5El>
|
||
)
|
||
}
|