Skip to content

Commit

Permalink
preventing errors when no documents
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexandre Chamla authored and Alexandre Chamla committed Sep 27, 2021
1 parent 2aecacc commit 871129c
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 8 deletions.
4 changes: 2 additions & 2 deletions components/Footer.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ export default function Header({ footer = [], }){
))}
</div>
<div className="mt-16 md:mt-16 xl:mt-0">
<h3 className="text-sm font-medium text-gray-900">{footer.data.newsletter_title}</h3>
<p className="mt-6 text-sm text-gray-500">{footer.data.newsletter_description}</p>
<h3 className="text-sm font-medium text-gray-900">{footer.data.newsletter_title ? footer.data.newsletter_title : <span>newsletter_title</span>}</h3>
<p className="mt-6 text-sm text-gray-500">{footer.data.newsletter_description ? footer.data.newsletter_description : <span>newsletter_description</span>}</p>
<form className="mt-2 flex sm:max-w-md">
<label htmlFor="email-address" className="sr-only">
Email address
Expand Down
2 changes: 1 addition & 1 deletion components/Header.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ function classNames(...classes) {
return classes.filter(Boolean).join(' ')
}

export default function Header({ menu = [], categories =[] }){
export default function Header({ menu = [], categories = [] }){
const [open, setOpen] = useState(false)
return (
<div className="bg-white">
Expand Down
10 changes: 8 additions & 2 deletions components/Layout.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,15 @@ const Layout = ({ children, menu, footer, categories }) => {
<Head>
<title> Prismic E-commerce Demo </title>
</Head>
<Header menu={menu} categories={categories}/>
{ menu.data ?
<Header menu={menu} categories={categories}/>
: <span/>
}
<main>{children}</main>
<Footer footer={footer}/>
{ footer.data ?
<Footer footer={footer}/>
: <span/>
}
<ExitPreviewButton />
</div>
)
Expand Down
9 changes: 6 additions & 3 deletions pages/_app.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,12 @@ export default class MyApp extends NextApp {
const client = Client();
const menu = (await client.getSingle("menu")) || {};
const footer = (await client.getSingle("footer")) || {};
const categoriesId = menu.data.menu_tabs.map(function(tab) {
return tab.tab.id
})
let categoriesId = [];
if(menu.data){
categoriesId = menu.data.menu_tabs.map(function(tab) {
return tab.tab.id
})
}
const categories = (await client.getByIDs(categoriesId)) || {};
const categoriesClean = categories.results.map(function(category) {
return {
Expand Down

1 comment on commit 871129c

@vercel
Copy link

@vercel vercel bot commented on 871129c Sep 27, 2021

Choose a reason for hiding this comment

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

Please sign in to comment.