diff --git a/src/dashboard/DomainSettings/DomainSettings.react.js b/src/dashboard/DomainSettings/DomainSettings.react.js index bd5b18c4f..cbb36dc13 100644 --- a/src/dashboard/DomainSettings/DomainSettings.react.js +++ b/src/dashboard/DomainSettings/DomainSettings.react.js @@ -41,6 +41,7 @@ class DomainSettings extends DashboardView { isUserVerified: false, canChangeCustomDomain: false, + canChangeSubdomain: false, showCardValidation: true, subdomainName: '', @@ -57,19 +58,12 @@ class DomainSettings extends DashboardView { updating: false, isEditing: false, hasToggleChanged: false, - canEdit: false, + canEdit: true, errorCustomDomain: null, successCustomDomain: null, errorUpdateWebHost: null, successUpdateWebHost: null, - - // Session verification states - isVerifyingSession: false, - sessionVerificationError: null, - verifiedSessionId: null, - showSuccessMessage: false, - }; this.onRefresh = this.onRefresh.bind(this); this.handleSubdomainChange = this.handleSubdomainChange.bind(this); @@ -80,8 +74,6 @@ class DomainSettings extends DashboardView { componentWillMount() { this.loadData(); - this.checkForStripeSession(); - this.getOwner(); } componentWillReceiveProps(nextProps, nextContext) { @@ -103,13 +95,11 @@ class DomainSettings extends DashboardView { this.loadData(); } - getOwner() { - this.setState({ canEdit: !!this.context.isOwner }); - } - async loadData() { + console.log("STATE", this.state); try { const response = await this.context.getCustomDomain(); + console.log("RESPONSE", response); this.setState({ domainSettings: response }); await this.loadHostSettings(response); } catch (error) { @@ -120,7 +110,7 @@ class DomainSettings extends DashboardView { } async loadHostSettings(response) { - const { hostSettings: appHostSettings, domains, canChangeCustomDomain, createdAt } = response; + const { hostSettings: appHostSettings, domains, canChangeCustomDomain, canChangeSubdomain, createdAt } = response; let customDomainArray = []; let subdomainName = ''; @@ -129,7 +119,6 @@ class DomainSettings extends DashboardView { let isActivated = false; let hasPermission = false; let isUserVerified = false; - let alertValidationCreditCard = true; if (domains && domains.length > 0) { customDomainArray = domains; @@ -151,9 +140,11 @@ class DomainSettings extends DashboardView { } hasPermission = (!response.featuresPermission || response.featuresPermission.webHostLiveQuery === 'Write'); + + console.log("response", createdAt); + if (response && ((appHostSettings.serverURL && appHostSettings.activated) || (createdAt && ((new Date() - new Date(createdAt)) > (6 * 30 * 24 * 60 * 60 * 1000))))) { isUserVerified = true; - alertValidationCreditCard = false; } if (!isUserVerified) { @@ -161,26 +152,22 @@ class DomainSettings extends DashboardView { const plan = await this.context.getAppPlanData(); if (plan && plan.planName && (plan.planName.indexOf('Free') < 0) && (plan.planName.indexOf('Public') < 0)) { isUserVerified = true; - alertValidationCreditCard = false; } else { const currentUser = AccountManager.currentUser(); if (currentUser && currentUser.verification.cardValidation) { isUserVerified = true; - alertValidationCreditCard = false; } } } catch (planError) { const currentUser = AccountManager.currentUser(); if (currentUser && currentUser.verification.cardValidation) { isUserVerified = true; - alertValidationCreditCard = false; } } } this.setState({ isUserVerified, - showCardValidation: alertValidationCreditCard, subdomainName, currentSubdomain, @@ -192,6 +179,7 @@ class DomainSettings extends DashboardView { hasPermission, canChangeCustomDomain, + canChangeSubdomain, }); } @@ -296,7 +284,9 @@ class DomainSettings extends DashboardView { }, 5000); }); } catch (error) { - this.setState({ errorUpdateWebHost: error.message || 'Something went wrong!' }, () => { + console.error('error updating web host', error); + + this.setState({ errorUpdateWebHost: error || 'Something went wrong!' }, () => { setTimeout(() => { this.setState({ errorUpdateWebHost: null }); }, 5000); @@ -309,111 +299,32 @@ class DomainSettings extends DashboardView { async verifyUser() { try { const user = await back4app2.me(); - if (user && user.verification.cardValidation) { - this.setState({ isUserVerified: true, showCardValidation: false }); + if (user) { + this.setState({ isUserVerified: true }); } } catch (e) { console.log('user validation failed!') } } - checkForStripeSession() { - const urlParams = new URLSearchParams(window.location.search); - const sessionId = urlParams.get('session_id'); - - if (sessionId && sessionId !== this.state.verifiedSessionId) { - this.verifyStripeSession(sessionId); - } - } - - async verifyStripeSession(sessionId) { - try { - this.setState({ - isVerifyingSession: true, - sessionVerificationError: null - }); - - await back4app2.stripeSessionStatus(sessionId); - - // Session verification successful - this.setState({ - isVerifyingSession: false, - verifiedSessionId: sessionId, - showSuccessMessage: true - }); - - const user = AccountManager.currentUser(); - user.verification.cardValidation = true; - AccountManager.setCurrentUser({ user }); - - // Show success message for 2 seconds, then close modal and update state - setTimeout(() => { - this.setState({ - showSuccessMessage: false, - isUserVerified: true, - showCardValidation: false - }); - }, 2000); - - } catch (error) { - console.error('Error verifying stripe session:', error); - - this.setState({ - isVerifyingSession: false, - sessionVerificationError: error.message || 'Failed to verify payment. Please try again.', - showCardValidation: true - }); - } finally { - // Clean up URL regardless of success or error - const url = new URL(window.location); - url.searchParams.delete('session_id'); - window.history.replaceState({}, '', url); - } - } - getDisplayContent() { let content = null; - if (this.state.isVerifyingSession || this.state.showSuccessMessage) { - content = } - > -
- {this.state.showSuccessMessage ? ( -
- -
Payment verification successful!
-
- ) : ( -
-
-
Loading...
-
- )} -
-
- } else if (this.state.showCardValidation) { + if ( + !this.state.canChangeSubdomain && !this.state.isActivated && this.state.currentSubdomain.trim().length === 0 && this.state.customDomainArray.length === 0) { content =
} + label={
} else if (this.state.isUserVerified) { content = <>
@@ -421,12 +332,21 @@ class DomainSettings extends DashboardView { label={