Skip to content

Validate custom domain name availability - #1114

Merged
fredrikekelund merged 6 commits into
trunkfrom
f26d/validate-domain-availability
Mar 24, 2025
Merged

Validate custom domain name availability#1114
fredrikekelund merged 6 commits into
trunkfrom
f26d/validate-domain-availability

Conversation

@fredrikekelund

Copy link
Copy Markdown
Contributor

Related issues

Proposed Changes

  • Validate custom domain name availability when adding or editing a site

Testing Instructions

  1. Have a site with a custom domain name
  2. Attempt to add a new site with the same custom domain name
  3. Ensure that there's a validation error preventing you from adding the new site
  4. Edit an existing site without a custom domain name
  5. Attempt to use the custom domain name from the first site
  6. Ensure that there's a validation error preventing you from submitting the form
  7. Attempt to edit the site with the custom domain
  8. Ensure that the editing modal doesn't open with a validation error

Pre-merge Checklist

  • Have you checked for TypeScript, React or other console errors?
@fredrikekelund
fredrikekelund requested a review from a team March 24, 2025 09:10
@fredrikekelund fredrikekelund self-assigned this Mar 24, 2025

@bcotrim bcotrim left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nice improvement! 👍

I don't like how we need to fetch the userData for each validation. It's probably outside of the scope of this issue, but now that we have Redux, I think it would be great if we could make our userData sync with a Redux store, fixing all issues similar to this one.

I added a comment with an issue I've found. Besides that I think the code is good to go, if we want to tackle the Redux change in the future.

Comment thread src/hooks/use-add-site.ts Outdated
const [ existingDomainNames, setExistingDomainNames ] = useState< string[] >( [] );
const [ enableHttps, setEnableHttps ] = useState( false );

useEffect( () => {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This is only loading the domains once.
So if you create a site with a custom domain and, without restarting the app, try to create another one using the same domain, it will allow it.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good catch, thanks 👍

@wojtekn wojtekn left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Works as expected. I get correct validation error in both Add site and Edit site forms.

Comment thread src/lib/domains.ts
};

export const validateDomainName = (
export const getDomainNameValidationError = (

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nice rename and validation improvements.

@fredrikekelund

Copy link
Copy Markdown
Contributor Author

it would be great if we could make our userData sync with a Redux store

Agreed 👍 We could probably remove a good chunk of the IPC methods if we did this and reduce the overall complexity. But yeah, it's definitely outside the scope of this PR

@fredrikekelund
fredrikekelund requested a review from bcotrim March 24, 2025 10:40

@bcotrim bcotrim left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Tested and confirmed the issue no longer happens, thanks for making the change!
LGTM 👍

@fredrikekelund
fredrikekelund merged commit ab99f5b into trunk Mar 24, 2025
@fredrikekelund
fredrikekelund deleted the f26d/validate-domain-availability branch March 24, 2025 11:12
.catch( () => {
// Do nothing
} );
}, [ selectedSite?.customDomain ] );

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It would be cool to extract this code into a useAvailableCustomDomains() hook to improve readability.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

4 participants