feat(release): prepare 1.1.0 candidate
This commit is contained in:
parent
5a34f66981
commit
5205dcdfa9
736 changed files with 115667 additions and 12203 deletions
|
|
@ -3,7 +3,7 @@
|
|||
// apps/web/src/components/billing/payple-manage-button.tsx
|
||||
// Payple 구독 관리 — payple-manage Edge Function 호출 (구독 취소)
|
||||
|
||||
import { useState } from 'react'
|
||||
import { useEffect, useState } from 'react'
|
||||
import { Button, CircularProgress, Alert, Box, Dialog, DialogTitle, DialogContent, DialogContentText, DialogActions } from '@mui/material'
|
||||
import SettingsIcon from '@mui/icons-material/Settings'
|
||||
import { getSupabaseBrowserClient } from '@/lib/supabase-browser'
|
||||
|
|
@ -13,6 +13,9 @@ export function PaypleManageButton(): React.ReactElement {
|
|||
const [error, setError] = useState<string | null>(null)
|
||||
const [confirmOpen, setConfirmOpen] = useState(false)
|
||||
const [success, setSuccess] = useState(false)
|
||||
const [ready, setReady] = useState(false)
|
||||
|
||||
useEffect(() => setReady(true), [])
|
||||
|
||||
async function handleCancel(): Promise<void> {
|
||||
setConfirmOpen(false)
|
||||
|
|
@ -20,15 +23,18 @@ export function PaypleManageButton(): React.ReactElement {
|
|||
setBusy(true)
|
||||
try {
|
||||
const supabase = getSupabaseBrowserClient()
|
||||
const { data: { session } } = await supabase.auth.getSession()
|
||||
const { data: { session }, error: sessionError } = await supabase.auth.getSession()
|
||||
|
||||
if (!session) {
|
||||
if (sessionError || !session) {
|
||||
setError('로그인이 필요합니다')
|
||||
return
|
||||
}
|
||||
|
||||
const baseUrl = process.env.NEXT_PUBLIC_SUPABASE_URL?.trim()
|
||||
if (!baseUrl) throw new Error('결제 서버 설정이 완료되지 않았습니다')
|
||||
|
||||
const response = await fetch(
|
||||
`${process.env.NEXT_PUBLIC_SUPABASE_URL}/functions/v1/payple-manage`,
|
||||
new URL('/functions/v1/payple-manage', baseUrl).toString(),
|
||||
{
|
||||
method: 'POST',
|
||||
headers: {
|
||||
|
|
@ -39,16 +45,21 @@ export function PaypleManageButton(): React.ReactElement {
|
|||
}
|
||||
)
|
||||
|
||||
const data = await response.json().catch(() => null) as { success?: unknown; cancel_at?: unknown } | null
|
||||
if (!response.ok) {
|
||||
const txt = await response.text()
|
||||
throw new Error(`구독 취소 실패: ${response.status} ${txt}`)
|
||||
throw new Error(response.status === 409
|
||||
? '구독 취소 확인이 필요합니다. 다시 요청하지 말고 고객센터에 문의해 주세요.'
|
||||
: '구독 취소를 완료하지 못했습니다.')
|
||||
}
|
||||
|
||||
const data = await response.json() as { success?: boolean; cancel_at?: string }
|
||||
if (data.success) {
|
||||
setSuccess(true)
|
||||
setTimeout(() => window.location.reload(), 2000)
|
||||
if (
|
||||
data?.success !== true
|
||||
|| typeof data.cancel_at !== 'string'
|
||||
|| !Number.isFinite(Date.parse(data.cancel_at))
|
||||
) {
|
||||
throw new Error('구독 취소 결과를 확인할 수 없습니다.')
|
||||
}
|
||||
setSuccess(true)
|
||||
window.setTimeout(() => window.location.reload(), 2000)
|
||||
} catch (e) {
|
||||
setError(e instanceof Error ? e.message : '알 수 없는 오류')
|
||||
} finally {
|
||||
|
|
@ -58,7 +69,7 @@ export function PaypleManageButton(): React.ReactElement {
|
|||
|
||||
if (success) {
|
||||
return (
|
||||
<Alert severity="info" variant="outlined" sx={{ fontSize: 12 }}>
|
||||
<Alert data-testid="payple-manage-success" severity="info" variant="outlined" sx={{ fontSize: 12 }}>
|
||||
구독이 취소되었습니다. 현재 결제 기간이 끝날 때까지 이용 가능합니다.
|
||||
</Alert>
|
||||
)
|
||||
|
|
@ -70,8 +81,9 @@ export function PaypleManageButton(): React.ReactElement {
|
|||
variant="outlined"
|
||||
size="small"
|
||||
startIcon={busy ? <CircularProgress size={14} /> : <SettingsIcon />}
|
||||
data-testid="payple-manage-open"
|
||||
onClick={() => setConfirmOpen(true)}
|
||||
disabled={busy}
|
||||
disabled={busy || !ready}
|
||||
>
|
||||
구독 관리
|
||||
</Button>
|
||||
|
|
@ -85,14 +97,14 @@ export function PaypleManageButton(): React.ReactElement {
|
|||
</DialogContent>
|
||||
<DialogActions>
|
||||
<Button onClick={() => setConfirmOpen(false)}>돌아가기</Button>
|
||||
<Button onClick={() => void handleCancel()} color="error" variant="contained">
|
||||
<Button data-testid="payple-manage-confirm" onClick={() => void handleCancel()} color="error" variant="contained">
|
||||
구독 취소
|
||||
</Button>
|
||||
</DialogActions>
|
||||
</Dialog>
|
||||
|
||||
{error && (
|
||||
<Alert severity="error" variant="outlined" sx={{ mt: 1, fontSize: 11 }}>
|
||||
<Alert data-testid="payple-manage-error" severity="error" variant="outlined" sx={{ mt: 1, fontSize: 11 }}>
|
||||
{error}
|
||||
</Alert>
|
||||
)}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue