Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions forms_pro/api/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,12 @@ def get_brand_logo() -> str:
str: The brand logo of the website or the default app logo if brand logo is not set.
"""
return str(get_app_logo())


@frappe.whitelist(allow_guest=True)
def get_website_settings() -> dict:
website_settings = frappe.get_doc("Website Settings")
form_settings = {
"disable_sign_up": website_settings.disable_signup,
}
return form_settings
9 changes: 8 additions & 1 deletion frontend/src/components/submission/PageHeader.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ const brandLogo = createResource({
auto: true,
});

const websiteSettings = createResource({
url: "forms_pro.api.settings.get_website_settings",
auto: true,
});

function redirectToLogin() {
window.location.href = `/login?redirect-to=${route.fullPath}`;
}
Expand All @@ -36,7 +41,9 @@ function redirectToLogin() {
</div>
</template>
</Popover>
<Button v-else @click="redirectToLogin">Login</Button>
<Button v-else-if="!websiteSettings.data?.disable_sign_up" @click="redirectToLogin">
Login
</Button>
Comment on lines +44 to +46

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

🧩 Analysis chain

🏁 Script executed:

find . -name "PageHeader.vue" -type f

Repository: BuildWithHussain/forms_pro

Length of output: 121


🌐 Web query:

frappe-ui createResource initial data value behavior undefined null

💡 Result:

Short answer: createResource leaves resource.data undefined until a successful fetch (or until you pass initialData). Set initialData (e.g. initialData: []) or guard for undefined (resource.data || []) and/or check resource.fetched or loading before reading resource.data. This prevents reads of undefined vs null and matches community examples.

References:

  • example using initialData with createResource (notifications store). [1]
  • forum reports where resource.data remains undefined until fetch completes (discussion and troubleshooting). [2][3]

Sources:
[1] gist: Frappe CRM frontend using createResource with initialData.
[2] Frappe forum: "Getting Undefined In CreateResource from Frappe-UI".
[3] Frappe forum: "Frappe-ui createResource data isn't updating in Vue component".


🏁 Script executed:

cat -n ./frontend/src/components/submission/PageHeader.vue | head -100

Repository: BuildWithHussain/forms_pro

Length of output: 2109


Avoid showing Login before settings resolve.
If websiteSettings.data is undefined (before the fetch completes), the condition !websiteSettings.data?.disable_sign_up evaluates to true, causing the Login button to appear even when sign‑up should be disabled. Guard on resolved data to prevent this brief visibility window.

✅ Suggested fix
-            <Button v-else-if="!websiteSettings.data?.disable_sign_up" `@click`="redirectToLogin">
+            <Button
+                v-else-if="websiteSettings.data && !websiteSettings.data.disable_sign_up"
+                `@click`="redirectToLogin"
+            >
                 Login
             </Button>
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
<Button v-else-if="!websiteSettings.data?.disable_sign_up" @click="redirectToLogin">
Login
</Button>
<Button
v-else-if="websiteSettings.data && !websiteSettings.data.disable_sign_up"
`@click`="redirectToLogin"
>
Login
</Button>
🤖 Prompt for AI Agents
In `@frontend/src/components/submission/PageHeader.vue` around lines 44 - 46, The
Login Button is rendered when websiteSettings.data is still undefined because
the current condition (!websiteSettings.data?.disable_sign_up) treats undefined
as allowed; change the guard to only evaluate after settings are resolved—for
example require websiteSettings.data to be truthy before checking
disable_sign_up. Update the conditional on the Button in PageHeader.vue to
ensure websiteSettings.data exists (e.g., websiteSettings.data &&
!websiteSettings.data.disable_sign_up or the component's resolved/loading flag)
so the Login button is not shown while settings are loading; keep the existing
redirectToLogin handler unchanged.

</div>
</div>
</template>