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 { 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,6 +116,7 @@ export default function Create() {
|
||||||
auth.login(window.location.pathname);
|
auth.login(window.location.pathname);
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
|
{template?.imageCount === 2 && (
|
||||||
<UploadCard
|
<UploadCard
|
||||||
disabled={!isLoggedIn}
|
disabled={!isLoggedIn}
|
||||||
imageUrl={image2}
|
imageUrl={image2}
|
||||||
|
|
@ -114,13 +127,14 @@ export default function Create() {
|
||||||
auth.login(window.location.pathname);
|
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 ? (
|
||||||
|
|
|
||||||
|
|
@ -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">
|
||||||
|
|
|
||||||
|
|
@ -38,6 +38,7 @@ export interface Template {
|
||||||
imagePrompt?: string; // 图片生成提示词
|
imagePrompt?: string; // 图片生成提示词
|
||||||
createdAt?: string; // 创建时间
|
createdAt?: string; // 创建时间
|
||||||
lastStripeSyncAt?: string; // 最后同步Stripe时间
|
lastStripeSyncAt?: string; // 最后同步Stripe时间
|
||||||
|
imageCount?: number; // 图片数量
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue