-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #15 from deco-sites/33770/traqueamento
- Loading branch information
Showing
10 changed files
with
524 additions
and
205 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { sendEvent } from "site/sdk/analytics.ts"; | ||
import type { AnalyticsEvent } from "apps/commerce/types.ts"; | ||
import type ExtendedAnalyticsEvent from "site/components/analytics.d.ts"; | ||
|
||
const SendEventOnClick = <E extends ExtendedAnalyticsEvent>( | ||
{ event, id }: { event: E; id: string }, | ||
) => ( | ||
<script | ||
type="module" | ||
dangerouslySetInnerHTML={{ | ||
__html: | ||
`addEventListener("load", () => {const element = document.getElementById("${id}"); element && element.addEventListener("click", () => (${sendEvent})(${ | ||
JSON.stringify(event) | ||
}));})`, | ||
}} | ||
/> | ||
); | ||
|
||
const SendEventOnLoad = <E extends AnalyticsEvent>({ event }: { event: E }) => ( | ||
<script | ||
type="module" | ||
dangerouslySetInnerHTML={{ | ||
__html: `addEventListener("load", () => (${sendEvent})(${ | ||
JSON.stringify(event) | ||
}))`, | ||
}} | ||
/> | ||
); | ||
|
||
export { SendEventOnClick, SendEventOnLoad }; |
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 |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { Device } from "@deco/deco/utils"; | ||
import { AnalyticsEvent } from "apps/commerce/types.ts"; | ||
|
||
type Common = { | ||
params: { | ||
device: Device; | ||
url: string; | ||
} | ||
}; | ||
|
||
type MenuClick = Common & { | ||
name: 'menu_click'; | ||
params: { | ||
name: string; | ||
} | ||
}; | ||
|
||
type SubmenuClick = Common & { | ||
name: 'submenu_click'; | ||
}; | ||
|
||
type MainBannerClick = Common & { | ||
name: 'banner_principal_click'; | ||
params: { | ||
index: number; | ||
} | ||
}; | ||
|
||
type MiniBannerClick = Common & { | ||
name: 'mini_banner_click'; | ||
}; | ||
|
||
type ExtendedAnalyticsEvent = | ||
AnalyticsEvent | ||
| MenuClick | ||
| SubmenuClick | ||
| MainBannerClick | ||
| MiniBannerClick | ||
; | ||
|
||
export default ExtendedAnalyticsEvent; |
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,48 +1,91 @@ | ||
import { IconArrowRightDropdown } from "../Icons/IconArrowRightDropdown.tsx"; | ||
import { SendEventOnClick } from "site/components/Analytics.tsx"; | ||
import { useId } from "site/sdk/useId.ts"; | ||
import { Submenu } from "./Menu.types.ts"; | ||
import { useDevice } from "@deco/deco/hooks"; | ||
|
||
interface Props { | ||
submenu: Submenu[] | null | undefined; | ||
} | ||
|
||
export function MenuMobileDetails({ submenu }: Props) { | ||
const device = useDevice(); | ||
|
||
return ( | ||
<div class="px-6"> | ||
{submenu?.map((item, index) => ( | ||
<details | ||
key={index} | ||
class="collapse rounded-none border-b border-secondary border-dashed group" | ||
> | ||
<summary class="text-xs text-accent py-4 font-bold !flex justify-between items-center"> | ||
{item.item[0]?.item || "Item"} | ||
<IconArrowRightDropdown /> | ||
</summary> | ||
<div> | ||
{item.item.map((subItem) => { | ||
if (subItem.highlight) return null; | ||
return ( | ||
<a | ||
key={subItem.item} | ||
href={subItem.href} | ||
class={`block text-accent font-medium text-[13px] mb-5`} | ||
> | ||
{subItem.item} | ||
</a> | ||
); | ||
})} | ||
|
||
{item.seeAll && ( | ||
<a | ||
key={item.item[0]?.item} | ||
href={item.item[0]?.href} | ||
class={`block font-bold underline text-primary text-[13px] mb-4`} | ||
> | ||
Ver mais | ||
</a> | ||
)} | ||
</div> | ||
</details> | ||
))} | ||
{submenu?.map((item, index) => { | ||
const seeAllID = useId(); | ||
|
||
return ( | ||
<details | ||
key={index} | ||
class="collapse rounded-none border-b border-secondary border-dashed group" | ||
> | ||
<summary class="text-xs text-accent py-4 font-bold !flex justify-between items-center"> | ||
{item.item[0]?.item || "Item"} | ||
<IconArrowRightDropdown/> | ||
</summary> | ||
|
||
<div> | ||
{item.item.map((subItem) => { | ||
if (subItem.highlight) return null; | ||
|
||
const itemID = useId(); | ||
|
||
return ( | ||
<> | ||
<a | ||
key={subItem.item} | ||
href={subItem.href} | ||
class={`block text-accent font-medium text-[13px] mb-5`} | ||
id={itemID} | ||
> | ||
{subItem.item} | ||
</a> | ||
|
||
<SendEventOnClick | ||
id={itemID} | ||
event={{ | ||
name: 'submenu_click', | ||
params: { | ||
name: subItem.item, | ||
url: subItem.href, | ||
device | ||
} | ||
}} | ||
/> | ||
</> | ||
); | ||
})} | ||
|
||
{item.seeAll && ( | ||
<> | ||
<a | ||
key={item.item[0]?.item} | ||
href={item.item[0]?.href} | ||
class={`block font-bold underline text-primary text-[13px] mb-4`} | ||
id={seeAllID} | ||
> | ||
Ver mais | ||
</a> | ||
|
||
<SendEventOnClick | ||
id={seeAllID} | ||
event={{ | ||
name: 'submenu_click', | ||
params: { | ||
name: 'Ver mais', | ||
url: item.item[0]?.href, | ||
device | ||
} | ||
}} | ||
/> | ||
</> | ||
)} | ||
</div> | ||
</details> | ||
); | ||
})} | ||
</div> | ||
); | ||
} |
Oops, something went wrong.