Skip to content

Commit

Permalink
Merge pull request #18 from ggindev/fix-type-error
Browse files Browse the repository at this point in the history
Fix type error in check-availability route
  • Loading branch information
ggindev authored Oct 20, 2024
2 parents ec302ec + 1ebda07 commit 1758bd0
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
3 changes: 3 additions & 0 deletions src/app/api/domains/check-availability/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ async function checkDomainAvailability(domain: string, providerUrl: string): Pro
if (providerUrl.includes('godaddy')) {
return data.available ?? false;
} else if (providerUrl.includes('whoisxmlapi')) {
if (!data.WhoisRecord) {
return false;
}
return data.WhoisRecord.domainAvailability === 'AVAILABLE';
} else {
throw new Error(ERROR_UNSUPPORTED_PROVIDER);
Expand Down
16 changes: 6 additions & 10 deletions src/components/DomainGeneratorForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ const DomainGeneratorForm: React.FC = () => {
const [isLoading, setIsLoading] = useState(false);
const [error, setError] = useState<string | null>(null);
const [availability, setAvailability] = useState<DomainAvailability>({});
const [favorites, setFavorites] = useState<string[]>([]);

const handleInputChange = (e: React.ChangeEvent<HTMLInputElement>) => {
const { name, value, type, checked } = e.target;
Expand Down Expand Up @@ -129,17 +130,12 @@ const DomainGeneratorForm: React.FC = () => {

const handleFavorite = async (domain: string) => {
try {
const response = await fetch('/api/favorites/add', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({ domain }),
});
if (!response.ok) {
throw new Error('Failed to add domain to favorites');
const favorites = JSON.parse(localStorage.getItem('favorites') || '[]');
if (!favorites.includes(domain)) {
favorites.push(domain);
localStorage.setItem('favorites', JSON.stringify(favorites));
setFavorites(prev => [...prev, domain]);
}
setFavorites(prev => [...prev, domain]);
} catch (error) {
console.error('Error adding domain to favorites:', error);
setError(ERROR_ADDING_FAVORITE);
Expand Down

0 comments on commit 1758bd0

Please sign in to comment.