-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: Copy and refactor nav (#107)
- Loading branch information
1 parent
b5e10bd
commit 8c1daf7
Showing
14 changed files
with
539 additions
and
347 deletions.
There are no files selected for viewing
128 changes: 91 additions & 37 deletions
128
apps/storefront/src/app/[locale]/(main)/_components/navigation.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,65 +1,9 @@ | ||
import type { MenuItem } from "@nimara/domain/objects/Menu"; | ||
import { loggingService } from "@nimara/infrastructure/logging/service"; | ||
export const isValidJson = (value: string) => { | ||
try { | ||
JSON.parse(value); | ||
|
||
interface Paths { | ||
page: { | ||
asPath: (params: { slug: string }) => string; | ||
}; | ||
search: { | ||
asPath: (params: { query: Record<string, string> }) => string; | ||
}; | ||
} | ||
//TO DO - handle validating internal url | ||
export const generateLinkUrl = (item: MenuItem, paths: Paths): string => { | ||
if (item.collection) { | ||
return paths.search.asPath({ | ||
query: { collection: item.collection.slug }, | ||
}); | ||
} | ||
if (item.category) { | ||
return paths.search.asPath({ | ||
query: { category: item.category.slug }, | ||
}); | ||
} | ||
if (item.page) { | ||
return paths.page.asPath({ slug: item.page.slug }); | ||
} | ||
if (item.url) { | ||
return item.url; | ||
} | ||
|
||
return "#"; | ||
}; | ||
|
||
const internalUrls = [ | ||
"https://nimara-dev.vercel.app", | ||
"https://nimara-stage.vercel.app", | ||
"https://nimara-prod.vercel.app", | ||
"http://localhost", | ||
"https://localhost", | ||
]; | ||
|
||
export const isInternalUrl = (url: string | null): boolean => { | ||
if (url === null) { | ||
return true; | ||
} catch (error) { | ||
return false; | ||
} | ||
if (url) { | ||
try { | ||
const parsedUrl = new URL(url); | ||
|
||
return internalUrls.some((internalUrl) => { | ||
const internalParsedUrl = new URL(internalUrl); | ||
|
||
return parsedUrl.hostname === internalParsedUrl.hostname; | ||
}); | ||
} catch (e) { | ||
loggingService.error("Given URL is not internal", { | ||
error: e, | ||
}); | ||
|
||
return false; | ||
} | ||
} | ||
|
||
return false; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.