Open platform to collect and prioritize feedback
refactor: use function component for signup page
goenning03a3fdaf77f8
diff --git a/app/services/sqlstore/postgres/tenant.go b/app/services/sqlstore/postgres/tenant.goindex a6b324cd5..dd701992f 100644--- a/app/services/sqlstore/postgres/tenant.go+++ b/app/services/sqlstore/postgres/tenant.go@@ -238,7 +238,7 @@ func createTenant(ctx context.Context, c *cmd.CreateTenant) error {}if env.IsBillingEnabled() {- trialEndsAt := time.Now().AddDate(0, 0, 30) // 30 days+ trialEndsAt := time.Now().AddDate(0, 0, 15) // 15 days_, err := trx.Execute(`INSERT INTO tenants_billing (tenant_id, trial_ends_at, status, paddle_subscription_id, paddle_plan_id)VALUES ($1, $2, $3, '', '')`, id, trialEndsAt, enum.BillingTrial)diff --git a/public/pages/SignUp/SignUp.page.tsx b/public/pages/SignUp/SignUp.page.tsxindex b29ccc5e5..939810b0a 100644--- a/public/pages/SignUp/SignUp.page.tsx+++ b/public/pages/SignUp/SignUp.page.tsx@@ -1,7 +1,8 @@-import React from "react"+import React, { useEffect, useState } from "react"import { SignInControl, Modal, Button, DisplayError, Form, Input, Message, LegalAgreement } from "@fider/components"import { jwt, actions, Failure, querystring, Fider } from "@fider/services"-import { Divider } from "@fider/components/layout"+import { Divider, HStack } from "@fider/components/layout"+import { useFider } from "@fider/hooks"interface OAuthUser {token: string@@ -9,61 +10,52 @@ interface OAuthUser {email: string}-interface SignUpPageState {- submitted: boolean- tenantName: string- legalAgreement: boolean- error?: Failure- name?: string- email?: string- subdomain: {- available: boolean- message?: string- value?: string- }+interface SubdomainState {+ name: string+ isAvailable: boolean+ message: string}-export default class SignUpPage extends React.Component<any, SignUpPageState> {- private user?: OAuthUser-- constructor(props: any) {- super(props)- this.state = {- submitted: false,- legalAgreement: false,- tenantName: "",- subdomain: { available: false },- }-- const token = querystring.get("token")- if (token) {- const data = jwt.decode(token)- if (data) {- this.user = {- token,- name: data["oauth/name"],- email: data["oauth/email"],- }+const SignUpPage = () => {+ const fider = useFider()++ const [isSubmitted, setIsSubmitted] = useState(false)+ const [isLegalAgreed, setIsLegalAgreed] = useState(false)+ const [tenantName, setTenantName] = useState("")+ const [userName, setUserName] = useState("")+ const [userEmail, setUserEmail] = useState("")+ const [subdomain, setSubdomain] = useState<SubdomainState>({ name: "", isAvailable: false, message: "" })+ const [error, setError] = useState<Failure | undefined>()++ let user: OAuthUser | undefined+ const token = querystring.get("token")+ if (token) {+ const data = jwt.decode(token)+ if (data) {+ user = {+ token,+ name: data["oauth/name"],+ email: data["oauth/email"],}}}- private confirm = async () => {+ const confirm = async () => {const result = await actions.createTenant({- token: this.user && this.user.token,- legalAgreement: this.state.legalAgreement,- tenantName: this.state.tenantName,- subdomain: this.state.subdomain.value,- name: this.state.name,- email: this.state.email,+ token: user && user.token,+ legalAgreement: isLegalAgreed,+ tenantName: tenantName,+ subdomain: subdomain.name,+ name: userName,+ email: userEmail,})if (result.ok) {- if (this.user) {- if (Fider.isSingleHostMode()) {+ if (user) {+ if (fider.isSingleHostMode()) {location.reload()} else {- let baseURL = `${location.protocol}//${this.state.subdomain.value}${Fider.settings.domain}`+ let baseURL = `${location.protocol}//${subdomain.name}${fider.settings.domain}`if (location.port) {baseURL = `${baseURL}:${location.port}`}@@ -71,128 +63,118 @@ export default class SignUpPage extends React.Component<any, SignUpPageState> {location.href = baseURL}} else {- this.setState({ submitted: true })+ setIsSubmitted(true)}} else if (result.error) {- this.setState({ error: result.error, submitted: false })+ setError(result.error)+ setIsSubmitted(false)}}- private timer?: number- private checkAvailability = (subdomain: string) => {- window.clearTimeout(this.timer)- this.timer = window.setTimeout(() => {- actions.checkAvailability(subdomain).then((result) => {- this.setState({- subdomain: {- value: subdomain,- available: !result.data.message,- message: result.data.message,- },- })- })- }, 500)- }-- private setSubdomain = async (subdomain: string) => {- this.setState(- {- subdomain: {- value: subdomain,- available: false,- },- },- this.checkAvailability.bind(this, subdomain)- )- }-- private onAgree = (agreed: boolean): void => {- this.setState({ legalAgreement: agreed })- }-- private setName = (name: string): void => {- this.setState({ name })+ const setSubdomainName = (value: string) => {+ setSubdomain({+ name: value,+ isAvailable: false,+ message: "",+ })}- private setEmail = (email: string): void => {- this.setState({ email })- }+ let timer: number | undefined+ useEffect(() => {+ setSubdomain({+ ...subdomain,+ isAvailable: false,+ message: "",+ })- private setTenantName = (tenantName: string): void => {- this.setState({ tenantName })- }+ if (subdomain.name != "") {+ timer = window.setTimeout(() => {+ actions.checkAvailability(subdomain.name).then((result) => {+ setSubdomain({+ ...subdomain,+ isAvailable: !result.data.message,+ message: result.data.message,+ })+ })+ }, 500)+ }+ return () => {+ window.clearTimeout(timer)+ }+ }, [subdomain.name])- private noop = () => {+ const noop = () => {// do nothing}- public render() {- const modal = (- <Modal.Window canClose={false} isOpen={this.state.submitted} onClose={this.noop}>- <Modal.Header>Thank you for registering!</Modal.Header>- <Modal.Content>- <p>- We have just sent a confirmation link to <b>{this.state.email}</b>.- </p>- <p>Click the link to complete the registration.</p>- </Modal.Content>- </Modal.Window>- )-- return (- <div id="p-signup" className="page container w-max-6xl">- {modal}- <div className="h-20 text-center mb-4">- <img className="logo" alt="Logo" src="https://getfider.com/images/logo-100x100.png" />- </div>+ const modal = (+ <Modal.Window canClose={false} isOpen={isSubmitted} onClose={noop}>+ <Modal.Header>Thank you for registering!</Modal.Header>+ <Modal.Content>+ <p>+ We have just sent a confirmation link to <b>{userEmail}</b>.+ </p>+ <p>Click the link to complete the registration.</p>+ </Modal.Content>+ </Modal.Window>+ )++ return (+ <div id="p-signup" className="page container w-max-6xl">+ {modal}+ <div className="h-20 text-center mb-4">+ <img className="logo" alt="Logo" src="https://getfider.com/images/logo-100x100.png" />+ </div>- <h3 className="text-display mb-2">1. Who are you?</h3>- <DisplayError fields={["token"]} error={this.state.error} />-- {this.user ? (- <p>- Hello, <b>{this.user.name}</b> {this.user.email && `(${this.user.email})`}- </p>- ) : (- <>- <p>We need to identify you to setup your new Fider account.</p>- <SignInControl useEmail={false} />- <Divider />- <Form error={this.state.error}>- <Input field="name" maxLength={100} onChange={this.setName} placeholder="Name" />- <Input field="email" maxLength={200} onChange={this.setEmail} placeholder="Email" />- </Form>- </>+ <h3 className="text-display mb-2">1. Who are you?</h3>+ <DisplayError fields={["token"]} error={error} />++ {user ? (+ <p>+ Hello, <b>{user.name}</b> {user.email && `(${user.email})`}+ </p>+ ) : (+ <>+ <p>We need to identify you to setup your new Fider account.</p>+ <SignInControl useEmail={false} />+ <Divider />+ <Form error={error}>+ <Input field="name" maxLength={100} onChange={setUserName} placeholder="Name" />+ <Input field="email" maxLength={200} onChange={setUserEmail} placeholder="Email" />+ </Form>+ </>+ )}++ <h3 className="text-display mb-2 mt-8">2. What is this Feedback Forum for?</h3>++ <Form error={error} className="mb-8">+ <Input field="tenantName" maxLength={60} onChange={setTenantName} placeholder="your company or product name" />+ {!Fider.isSingleHostMode() && (+ <Input field="subdomain" maxLength={40} onChange={setSubdomainName} placeholder="subdomain" suffix={fider.settings.domain}>+ {subdomain.isAvailable && (+ <Message className="mt-2" type="success" showIcon={true}>+ This subdomain is available!+ </Message>+ )}+ {subdomain.message && (+ <Message className="mt-2" type="error" showIcon={true}>+ {subdomain.message}+ </Message>+ )}+ </Input>)}- <h3 className="text-display mb-2 mt-8">2. What is this Feedback Forum for?</h3>-- <Form error={this.state.error} className="mb-8">- <Input field="tenantName" maxLength={60} onChange={this.setTenantName} placeholder="your company or product name" />- {!Fider.isSingleHostMode() && (- <Input field="subdomain" maxLength={40} onChange={this.setSubdomain} placeholder="subdomain" suffix={Fider.settings.domain}>- {this.state.subdomain.available && (- <Message className="mt-2" type="success" showIcon={true}>- This subdomain is available!- </Message>- )}- {this.state.subdomain.message && (- <Message className="mt-2" type="error" showIcon={true}>- {this.state.subdomain.message}- </Message>- )}- </Input>- )}- </Form>-- <Form error={this.state.error} className="mb-4">- <LegalAgreement onChange={this.onAgree} />- </Form>-- <Button variant="primary" size="large" onClick={this.confirm}>- Confirm- </Button>- </div>- )- }+ <div className="mt-4">+ <LegalAgreement onChange={setIsLegalAgreed} />+ </div>+ </Form>++ <Button variant="primary" size="large" onClick={confirm}>+ Confirm+ </Button>+ {fider.settings.isBillingEnabled && <div className="mt-2 text-muted">Your trial starts today and ends in 15 days.</div>}+ </div>+ )}++export default SignUpPage