mirror of
https://github.com/Motion-Games/MotionWebStudio.git
synced 2026-04-21 09:00:53 +02:00
stripe
This commit is contained in:
@@ -23,48 +23,39 @@ export const ProfileCompleter: React.FC = () => {
|
||||
const checkProfile = async () => {
|
||||
setChecking(true);
|
||||
|
||||
// --- DEMO MODE ---
|
||||
if (!isSupabaseConfigured) {
|
||||
const checkMetadataFallback = () => {
|
||||
const meta = user.user_metadata || {};
|
||||
if (!meta.first_name || !meta.last_name || !meta.date_of_birth) {
|
||||
const hasRequiredData = meta.first_name && meta.last_name && meta.date_of_birth;
|
||||
|
||||
if (!hasRequiredData) {
|
||||
setIsOpen(true);
|
||||
if (meta.first_name) setFirstName(meta.first_name);
|
||||
if (meta.last_name) setLastName(meta.last_name);
|
||||
if (meta.date_of_birth) setDateOfBirth(meta.date_of_birth);
|
||||
if (meta.first_name) setFirstName(meta.first_name);
|
||||
if (meta.last_name) setLastName(meta.last_name);
|
||||
if (meta.date_of_birth) setDateOfBirth(meta.date_of_birth);
|
||||
}
|
||||
};
|
||||
|
||||
if (!isSupabaseConfigured) {
|
||||
checkMetadataFallback();
|
||||
setChecking(false);
|
||||
return;
|
||||
}
|
||||
// -----------------
|
||||
|
||||
try {
|
||||
const { data, error } = await supabase
|
||||
const { data, error: fetchError } = await supabase
|
||||
.from('profiles')
|
||||
.select('first_name, last_name, date_of_birth')
|
||||
.eq('id', user.id)
|
||||
.maybeSingle();
|
||||
|
||||
if (error) {
|
||||
console.error('Error checking profile:', error.message || error);
|
||||
// If DB check fails, fallback to metadata to see if we should block the user.
|
||||
// This prevents locking the user out if the DB is temporarily unavailable or misconfigured,
|
||||
// provided they have the data in their auth metadata.
|
||||
const meta = user.user_metadata || {};
|
||||
const hasMetadata = meta.first_name && meta.last_name && meta.date_of_birth;
|
||||
|
||||
if (!hasMetadata) {
|
||||
setIsOpen(true);
|
||||
if (meta.first_name) setFirstName(meta.first_name);
|
||||
if (meta.last_name) setLastName(meta.last_name);
|
||||
if (meta.date_of_birth) setDateOfBirth(meta.date_of_birth);
|
||||
}
|
||||
if (fetchError) {
|
||||
// Ha hálózati hiba van (pl. adblocker vagy CORS), a metadata-ra hagyatkozunk csendben
|
||||
checkMetadataFallback();
|
||||
return;
|
||||
}
|
||||
|
||||
// If no profile exists, or names/dob are missing
|
||||
if (!data || !data.first_name || !data.last_name || !data.date_of_birth) {
|
||||
setIsOpen(true);
|
||||
// Pre-fill if partial data exists
|
||||
if (data?.first_name) setFirstName(data.first_name);
|
||||
else if (user.user_metadata?.first_name) setFirstName(user.user_metadata.first_name);
|
||||
|
||||
@@ -75,7 +66,13 @@ export const ProfileCompleter: React.FC = () => {
|
||||
else if (user.user_metadata?.date_of_birth) setDateOfBirth(user.user_metadata.date_of_birth);
|
||||
}
|
||||
} catch (err: any) {
|
||||
console.error('Unexpected error in ProfileCompleter:', err);
|
||||
// Hálózat-specifikus hibák esetén nem logolunk noisyt
|
||||
if (err instanceof TypeError && err.message.includes('fetch')) {
|
||||
checkMetadataFallback();
|
||||
} else {
|
||||
console.debug('Supabase connection issue, using metadata fallback.');
|
||||
checkMetadataFallback();
|
||||
}
|
||||
} finally {
|
||||
setChecking(false);
|
||||
}
|
||||
@@ -96,11 +93,8 @@ export const ProfileCompleter: React.FC = () => {
|
||||
}
|
||||
|
||||
try {
|
||||
// --- DEMO MODE UPDATE ---
|
||||
if (!isSupabaseConfigured && user) {
|
||||
await new Promise(resolve => setTimeout(resolve, 800)); // Fake delay
|
||||
|
||||
// Update local storage session
|
||||
await new Promise(resolve => setTimeout(resolve, 800));
|
||||
const storedSession = localStorage.getItem('demo_user_session');
|
||||
if (storedSession) {
|
||||
const parsed = JSON.parse(storedSession);
|
||||
@@ -111,15 +105,13 @@ export const ProfileCompleter: React.FC = () => {
|
||||
date_of_birth: dateOfBirth
|
||||
};
|
||||
localStorage.setItem('demo_user_session', JSON.stringify(parsed));
|
||||
refreshDemoUser(); // Refresh context
|
||||
refreshDemoUser();
|
||||
}
|
||||
setIsOpen(false);
|
||||
return;
|
||||
}
|
||||
// ------------------------
|
||||
|
||||
if (user) {
|
||||
// 1. Update Profile Table
|
||||
const { error: dbError } = await supabase
|
||||
.from('profiles')
|
||||
.upsert({
|
||||
@@ -133,7 +125,6 @@ export const ProfileCompleter: React.FC = () => {
|
||||
|
||||
if (dbError) throw dbError;
|
||||
|
||||
// 2. Update Auth Metadata (optional, but good for consistency)
|
||||
await supabase.auth.updateUser({
|
||||
data: {
|
||||
first_name: firstName,
|
||||
@@ -143,8 +134,6 @@ export const ProfileCompleter: React.FC = () => {
|
||||
});
|
||||
|
||||
setIsOpen(false);
|
||||
// We do not reload here to avoid infinite loops if checks fail on reload.
|
||||
// The state close is enough.
|
||||
}
|
||||
} catch (err: any) {
|
||||
console.error('Error updating profile:', err);
|
||||
@@ -164,9 +153,7 @@ export const ProfileCompleter: React.FC = () => {
|
||||
<User className="w-8 h-8 text-white" />
|
||||
</div>
|
||||
<h2 className="text-2xl font-bold">Hiányzó Adatok</h2>
|
||||
<p className="text-blue-100 text-sm mt-2">
|
||||
Kérjük, a folytatáshoz adja meg a hiányzó adatait.
|
||||
</p>
|
||||
<p className="text-blue-100 text-sm mt-2">Kérjük, a folytatáshoz adja meg a hiányzó adatait.</p>
|
||||
</div>
|
||||
|
||||
<div className="p-8">
|
||||
@@ -177,71 +164,33 @@ export const ProfileCompleter: React.FC = () => {
|
||||
<span>{error}</span>
|
||||
</div>
|
||||
)}
|
||||
|
||||
<div className="space-y-4">
|
||||
<div>
|
||||
<label htmlFor="comp_lastname" className="block text-sm font-medium text-gray-700 mb-1">
|
||||
Vezetéknév
|
||||
</label>
|
||||
<input
|
||||
id="comp_lastname"
|
||||
type="text"
|
||||
value={lastName}
|
||||
onChange={(e) => setLastName(e.target.value)}
|
||||
className="w-full px-4 py-3 rounded-lg border border-gray-300 focus:ring-2 focus:ring-primary focus:border-transparent outline-none transition-all bg-white text-gray-900"
|
||||
placeholder="Kovács"
|
||||
required
|
||||
/>
|
||||
<label htmlFor="comp_lastname" className="block text-sm font-medium text-gray-700 mb-1">Vezetéknév</label>
|
||||
<input id="comp_lastname" type="text" value={lastName} onChange={(e) => setLastName(e.target.value)} className="w-full px-4 py-3 rounded-lg border border-gray-300 focus:ring-2 focus:ring-primary focus:border-transparent outline-none transition-all bg-white text-gray-900" placeholder="Kovács" required />
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label htmlFor="comp_firstname" className="block text-sm font-medium text-gray-700 mb-1">
|
||||
Keresztnév
|
||||
</label>
|
||||
<input
|
||||
id="comp_firstname"
|
||||
type="text"
|
||||
value={firstName}
|
||||
onChange={(e) => setFirstName(e.target.value)}
|
||||
className="w-full px-4 py-3 rounded-lg border border-gray-300 focus:ring-2 focus:ring-primary focus:border-transparent outline-none transition-all bg-white text-gray-900"
|
||||
placeholder="János"
|
||||
required
|
||||
/>
|
||||
<label htmlFor="comp_firstname" className="block text-sm font-medium text-gray-700 mb-1">Keresztnév</label>
|
||||
<input id="comp_firstname" type="text" value={firstName} onChange={(e) => setFirstName(e.target.value)} className="w-full px-4 py-3 rounded-lg border border-gray-300 focus:ring-2 focus:ring-primary focus:border-transparent outline-none transition-all bg-white text-gray-900" placeholder="János" required />
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label htmlFor="comp_dob" className="block text-sm font-medium text-gray-700 mb-1">
|
||||
Születési dátum
|
||||
</label>
|
||||
<label htmlFor="comp_dob" className="block text-sm font-medium text-gray-700 mb-1">Születési dátum</label>
|
||||
<div className="relative">
|
||||
<input
|
||||
id="comp_dob"
|
||||
type="date"
|
||||
value={dateOfBirth}
|
||||
onChange={(e) => setDateOfBirth(e.target.value)}
|
||||
className="w-full px-4 py-3 rounded-lg border border-gray-300 focus:ring-2 focus:ring-primary focus:border-transparent outline-none transition-all bg-white text-gray-900"
|
||||
required
|
||||
/>
|
||||
<input id="comp_dob" type="date" value={dateOfBirth} onChange={(e) => setDateOfBirth(e.target.value)} className="w-full px-4 py-3 rounded-lg border border-gray-300 focus:ring-2 focus:ring-primary focus:border-transparent outline-none transition-all bg-white text-gray-900" required />
|
||||
<div className="absolute inset-y-0 right-0 pr-3 flex items-center pointer-events-none">
|
||||
<Calendar className="h-5 w-5 text-gray-400" />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="pt-2">
|
||||
<Button type="submit" fullWidth disabled={loading} className="flex justify-center items-center">
|
||||
{loading ? 'Mentés...' : (
|
||||
<>
|
||||
Adatok Mentése <Save className="ml-2 w-4 h-4" />
|
||||
</>
|
||||
<>Adatok Mentése <Save className="ml-2 w-4 h-4" /></>
|
||||
)}
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
<p className="text-xs text-center text-gray-500">
|
||||
Ezekre az adatokra a számlázáshoz és a kapcsolattartáshoz van szükségünk.
|
||||
</p>
|
||||
<p className="text-xs text-center text-gray-500">Ezekre az adatokra a számlázáshoz és a kapcsolattartáshoz van szükségünk.</p>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user