fix: x
This commit is contained in:
parent
c162612e62
commit
f668715c41
|
|
@ -1,4 +1,4 @@
|
|||
import { api } from '@/services/api';
|
||||
import { api, Template } from '@/services/api';
|
||||
import { auth } from '@/services/auth';
|
||||
import { useEffect, useState } from 'react';
|
||||
import { useParams } from 'react-router-dom';
|
||||
|
|
@ -10,9 +10,10 @@ import './index.css';
|
|||
export default function Create() {
|
||||
const { templateCode } = useParams();
|
||||
const [isLoggedIn, setIsLoggedIn] = useState<boolean>(false);
|
||||
|
||||
const [loginRedirecting, setLoginRedirecting] = useState(false);
|
||||
|
||||
const [template, setTemplate] = useState<Template | null>(null);
|
||||
|
||||
useEffect(() => {
|
||||
const checkLogin = async () => {
|
||||
// Check login status, including OAuth 2.0 callback handling
|
||||
|
|
@ -22,6 +23,17 @@ export default function Create() {
|
|||
checkLogin();
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
const fetchTemplate = async () => {
|
||||
if (!templateCode) {
|
||||
return;
|
||||
}
|
||||
const template = await api.getTemplate(templateCode);
|
||||
setTemplate(template);
|
||||
};
|
||||
fetchTemplate();
|
||||
}, [templateCode]);
|
||||
|
||||
const { t } = useI18n();
|
||||
|
||||
const [loading, setLoading] = useState(false);
|
||||
|
|
@ -45,7 +57,7 @@ export default function Create() {
|
|||
alert('Template code not set');
|
||||
return;
|
||||
}
|
||||
if (!image1 || !image2) {
|
||||
if (!image1 || (template?.imageCount === 2 && !image2)) {
|
||||
alert('Upload two images');
|
||||
return;
|
||||
}
|
||||
|
|
@ -64,7 +76,7 @@ export default function Create() {
|
|||
templateCode: templateCode,
|
||||
metadata: {
|
||||
cb_url: cbUrl,
|
||||
imageUrls: [image1, image2],
|
||||
imageUrls: [image1, image2 || ''],
|
||||
},
|
||||
});
|
||||
if (checkout && checkout.url) {
|
||||
|
|
@ -104,23 +116,25 @@ export default function Create() {
|
|||
auth.login(window.location.pathname);
|
||||
}}
|
||||
/>
|
||||
<UploadCard
|
||||
disabled={!isLoggedIn}
|
||||
imageUrl={image2}
|
||||
title={t('friendsPhoto.selectFriendPhoto')}
|
||||
onUploadSuccess={setImage2}
|
||||
onLogin={() => {
|
||||
setLoginRedirecting(true);
|
||||
auth.login(window.location.pathname);
|
||||
}}
|
||||
/>
|
||||
{template?.imageCount === 2 && (
|
||||
<UploadCard
|
||||
disabled={!isLoggedIn}
|
||||
imageUrl={image2}
|
||||
title={t('friendsPhoto.selectFriendPhoto')}
|
||||
onUploadSuccess={setImage2}
|
||||
onLogin={() => {
|
||||
setLoginRedirecting(true);
|
||||
auth.login(window.location.pathname);
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{/* 固定底部按钮 */}
|
||||
<div className="submit-section">
|
||||
<button
|
||||
className={`submit-button ${(!image1 || !image2 || loading) && isLoggedIn ? 'disabled' : ''}`}
|
||||
disabled={(!image1 || !image2 || loading) && isLoggedIn}
|
||||
className={`submit-button ${(!image1 || (template?.imageCount === 2 && !image2) || loading) && isLoggedIn ? 'disabled' : ''}`}
|
||||
disabled={(!image1 || (template?.imageCount === 2 && !image2) || loading) && isLoggedIn}
|
||||
onClick={handleSubmit}
|
||||
>
|
||||
{isLoggedIn === false ? (
|
||||
|
|
|
|||
|
|
@ -34,7 +34,7 @@ export default function Home() {
|
|||
return (
|
||||
<div className="home">
|
||||
<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 className="home-scroll">
|
||||
<div className="template-grid">
|
||||
|
|
|
|||
|
|
@ -38,6 +38,7 @@ export interface Template {
|
|||
imagePrompt?: string; // 图片生成提示词
|
||||
createdAt?: string; // 创建时间
|
||||
lastStripeSyncAt?: string; // 最后同步Stripe时间
|
||||
imageCount?: number; // 图片数量
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Reference in New Issue