This commit is contained in:
iHeyTang 2025-09-29 15:59:51 +08:00
parent c162612e62
commit f668715c41
3 changed files with 32 additions and 17 deletions

View File

@ -1,4 +1,4 @@
import { api } from '@/services/api'; import { api, Template } from '@/services/api';
import { auth } from '@/services/auth'; import { auth } from '@/services/auth';
import { useEffect, useState } from 'react'; import { useEffect, useState } from 'react';
import { useParams } from 'react-router-dom'; import { useParams } from 'react-router-dom';
@ -10,9 +10,10 @@ import './index.css';
export default function Create() { export default function Create() {
const { templateCode } = useParams(); const { templateCode } = useParams();
const [isLoggedIn, setIsLoggedIn] = useState<boolean>(false); const [isLoggedIn, setIsLoggedIn] = useState<boolean>(false);
const [loginRedirecting, setLoginRedirecting] = useState(false); const [loginRedirecting, setLoginRedirecting] = useState(false);
const [template, setTemplate] = useState<Template | null>(null);
useEffect(() => { useEffect(() => {
const checkLogin = async () => { const checkLogin = async () => {
// Check login status, including OAuth 2.0 callback handling // Check login status, including OAuth 2.0 callback handling
@ -22,6 +23,17 @@ export default function Create() {
checkLogin(); checkLogin();
}, []); }, []);
useEffect(() => {
const fetchTemplate = async () => {
if (!templateCode) {
return;
}
const template = await api.getTemplate(templateCode);
setTemplate(template);
};
fetchTemplate();
}, [templateCode]);
const { t } = useI18n(); const { t } = useI18n();
const [loading, setLoading] = useState(false); const [loading, setLoading] = useState(false);
@ -45,7 +57,7 @@ export default function Create() {
alert('Template code not set'); alert('Template code not set');
return; return;
} }
if (!image1 || !image2) { if (!image1 || (template?.imageCount === 2 && !image2)) {
alert('Upload two images'); alert('Upload two images');
return; return;
} }
@ -64,7 +76,7 @@ export default function Create() {
templateCode: templateCode, templateCode: templateCode,
metadata: { metadata: {
cb_url: cbUrl, cb_url: cbUrl,
imageUrls: [image1, image2], imageUrls: [image1, image2 || ''],
}, },
}); });
if (checkout && checkout.url) { if (checkout && checkout.url) {
@ -104,23 +116,25 @@ export default function Create() {
auth.login(window.location.pathname); auth.login(window.location.pathname);
}} }}
/> />
<UploadCard {template?.imageCount === 2 && (
disabled={!isLoggedIn} <UploadCard
imageUrl={image2} disabled={!isLoggedIn}
title={t('friendsPhoto.selectFriendPhoto')} imageUrl={image2}
onUploadSuccess={setImage2} title={t('friendsPhoto.selectFriendPhoto')}
onLogin={() => { onUploadSuccess={setImage2}
setLoginRedirecting(true); onLogin={() => {
auth.login(window.location.pathname); setLoginRedirecting(true);
}} auth.login(window.location.pathname);
/> }}
/>
)}
</div> </div>
{/* 固定底部按钮 */} {/* 固定底部按钮 */}
<div className="submit-section"> <div className="submit-section">
<button <button
className={`submit-button ${(!image1 || !image2 || loading) && isLoggedIn ? 'disabled' : ''}`} className={`submit-button ${(!image1 || (template?.imageCount === 2 && !image2) || loading) && isLoggedIn ? 'disabled' : ''}`}
disabled={(!image1 || !image2 || loading) && isLoggedIn} disabled={(!image1 || (template?.imageCount === 2 && !image2) || loading) && isLoggedIn}
onClick={handleSubmit} onClick={handleSubmit}
> >
{isLoggedIn === false ? ( {isLoggedIn === false ? (

View File

@ -34,7 +34,7 @@ export default function Home() {
return ( return (
<div className="home"> <div className="home">
<div className="home-header"> <div className="home-header">
New User 50% Off : <span className="coupon-text">BESTAI1ST</span> New User 50% Off : <span className="coupon-text">NEWUSER</span>
</div> </div>
<div className="home-scroll"> <div className="home-scroll">
<div className="template-grid"> <div className="template-grid">

View File

@ -38,6 +38,7 @@ export interface Template {
imagePrompt?: string; // 图片生成提示词 imagePrompt?: string; // 图片生成提示词
createdAt?: string; // 创建时间 createdAt?: string; // 创建时间
lastStripeSyncAt?: string; // 最后同步Stripe时间 lastStripeSyncAt?: string; // 最后同步Stripe时间
imageCount?: number; // 图片数量
} }
/** /**