Skip to content

Commit

Permalink
Merge pull request #745 from CodeForAfrica/fix/roboshield_social_link
Browse files Browse the repository at this point in the history
Fix @/roboshield social links
  • Loading branch information
kilemensi committed Jun 28, 2024
2 parents 26d688c + 8357018 commit 2e4999d
Show file tree
Hide file tree
Showing 10 changed files with 135 additions and 88 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,7 @@ import React, { ForwardedRef } from "react";

import NavBarNavList from "@/roboshield/components/NavBarNavList";
import NextImageButton from "@/roboshield/components/NextImageButton";

interface SocialLinks {
platform: string;
url: string;
}
import type { SocialMediaLink } from "@/roboshield/components/SocialMediaLinkIcon";

interface Menu {
label: string;
Expand All @@ -16,7 +12,7 @@ interface Menu {
interface Props extends Grid2Props {
logo: any;
menus: Menu[];
socialLinks: SocialLinks[];
socialLinks: SocialMediaLink[];
}
const DesktopNavBar = React.forwardRef(function DesktopNavBar(
props: Props,
Expand Down
3 changes: 2 additions & 1 deletion apps/roboshield/src/components/Footer/Footer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@ import RichText from "@/roboshield/components/RichText";
import type { Children } from "@/roboshield/components/RichText";
import FooterDescription from "./FooterDescription";
import { Partner } from "@/roboshield/lib/data/payload.types";
import type { SocialMediaLink } from "@/roboshield/components/SocialMediaLinkIcon";

export interface FooterProps {
connect: {
links: { url: string; platform: string }[];
links: SocialMediaLink[];
title: string;
};
description: Children;
Expand Down
8 changes: 2 additions & 6 deletions apps/roboshield/src/components/MobileNavBar/MobileNavBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,7 @@ import menuIcon from "@/roboshield/assets/icons/menu-icon.svg";
import CloseIcon from "@/roboshield/assets/icons/Type=x, Size=24, Color=CurrentColor.svg";
import NavBarNavList from "@/roboshield/components/NavBarNavList";
import NextImageButton from "@/roboshield/components/NextImageButton";

interface SocialLinks {
platform: string;
url: string;
}
import type { SocialMediaLink } from "@/roboshield/components/SocialMediaLinkIcon";

interface Menu {
label: string;
Expand All @@ -28,7 +24,7 @@ interface Menu {
interface Props extends Grid2Props {
logo: any;
menus: Menu[];
socialLinks: SocialLinks[];
socialLinks: SocialMediaLink[];
}

const DialogContainer = styled(Dialog)(({ theme: { palette, spacing } }) => ({
Expand Down
8 changes: 2 additions & 6 deletions apps/roboshield/src/components/NavBar/NavBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,7 @@ import React from "react";

import DesktopNavBar from "@/roboshield/components/DesktopNavBar";
import MobileNavBar from "@/roboshield/components/MobileNavBar";

interface SocialLinks {
platform: string;
url: string;
}
import type { SocialMediaLink } from "@/roboshield/components/SocialMediaLinkIcon";

interface Menu {
label: string;
Expand All @@ -16,7 +12,7 @@ interface Menu {
interface Props {
logo: any;
menus: Menu[];
socialLinks: SocialLinks[];
socialLinks: SocialMediaLink[];
}
function NavBar({ logo, menus, socialLinks }: Props) {
return (
Expand Down
45 changes: 15 additions & 30 deletions apps/roboshield/src/components/NavBarNavList/NavBarNavList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,12 @@ import { Link } from "@commons-ui/next";
import { LinkProps, SvgIcon } from "@mui/material";
import React, { ElementType, FC } from "react";

import GitHubIcon from "@/roboshield/assets/icons/Type=github, Size=24, Color=CurrentColor.svg";
import NavListItem from "@/roboshield/components/NavListItem";

const platformToIconMap: {
[key: string]: ElementType<any>;
} = {
Github: GitHubIcon,
};
import SocialMediaLinkIcon from "@/roboshield/components/SocialMediaLinkIcon";
import type { SocialMediaLink } from "@/roboshield/components/SocialMediaLinkIcon";

interface NavListItemProps extends LinkProps {}

interface SocialLinks {
platform: string;
url: string;
}

interface Menu {
label: string;
href: string;
Expand All @@ -28,7 +18,7 @@ interface Props {
NavListItemProps?: NavListItemProps;
direction?: string;
menus?: Menu[];
socialLinks?: SocialLinks[];
socialLinks?: SocialMediaLink[];
}

const NavBarNavList: FC<Props> = React.forwardRef(
Expand All @@ -53,7 +43,7 @@ const NavBarNavList: FC<Props> = React.forwardRef(
{...NavListItemProps}
href={item.href}
sx={{
typography: { md: "body1Bold" },
typography: { md: "body3" },
"&:hover, &:active, &:focus, &:focus-within": {
textDecoration: "none",
color: { xs: "inherit", md: "primary.main" },
Expand All @@ -66,29 +56,24 @@ const NavBarNavList: FC<Props> = React.forwardRef(
</NavListItem>
))}
{socialLinks?.map(({ platform, url }) => {
const Icon = platformToIconMap[platform];
if (!Icon) {
return null;
}
return (
<NavListItem key={platform}>
<Link
href={url}
<SocialMediaLinkIcon
url={url}
platform={platform}
variant="h3"
IconProps={{
fontSize: "inherit",
sx: {
fill: { xs: "none" },
mt: direction === "column" ? 0 : 1,
},
}}
sx={{
color: { xs: "inherit" },
typography: { md: "h5" },
}}
>
<SvgIcon
component={Icon}
fontSize="inherit"
sx={{
fill: { xs: "none" },
mt: direction === "column" ? 0 : 1,
}}
/>
</Link>
/>
</NavListItem>
);
})}
Expand Down
11 changes: 3 additions & 8 deletions apps/roboshield/src/components/Page/Page.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
import React from "react";

import type { FooterProps } from "@/roboshield/components/Footer";
import Footer from "@/roboshield/components/Footer";

import type { FooterProps } from "@/roboshield/components/Footer";
import NavBar from "@/roboshield/components/NavBar";

interface SocialLinks {
platform: string;
url: string;
}
import type { SocialMediaLink } from "@/roboshield/components/SocialMediaLinkIcon";

interface Menu {
label: string;
Expand All @@ -23,7 +18,7 @@ interface Menu {
interface Navbar {
logo: any;
menus: Menu[];
socialLinks: SocialLinks[];
socialLinks: SocialMediaLink[];
}
interface Footer {
logo: any;
Expand Down
22 changes: 22 additions & 0 deletions apps/roboshield/src/components/SocialMediaLinkIcon/LinkIcon.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { Link, RichTypography } from "@commons-ui/next";
import { Grid, SvgIcon } from "@mui/material";
import type { LinkProps, SvgIconProps } from "@mui/material";
import React from "react";

interface LinkIconProps extends LinkProps {
IconProps: SvgIconProps;
}

const LinkIcon = React.forwardRef(function LinkIcon(
{ IconProps, ...props }: LinkIconProps,
ref: React.ForwardedRef<HTMLAnchorElement>,
) {
return (
<Link {...props} ref={ref}>
<SvgIcon {...IconProps} />
</Link>
);
});

export type { LinkIconProps };
export default LinkIcon;
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import { Link, RichTypography } from "@commons-ui/next";
import { Grid, SvgIcon } from "@mui/material";
import React from "react";

import FacebookIcon from "@/roboshield/assets/icons/Type=facebook, Size=24, Color=CurrentColor.svg";
import GitHubIcon from "@/roboshield/assets/icons/Type=github, Size=24, Color=CurrentColor.svg";
import InstagramIcon from "@/roboshield/assets/icons/Type=instagram, Size=24, Color=CurrentColor.svg";
import LinkedInIcon from "@/roboshield/assets/icons/Type=linkedin, Size=24, Color=CurrentColor.svg";
import SlackIcon from "@/roboshield/assets/icons/Type=slack, Size=24, Color=CurrentColor.svg";
import TwitterIcon from "@/roboshield/assets/icons/Type=twitter, Size=24, Color=CurrentColor.svg";

import LinkIcon from "./LinkIcon";
import type { LinkIconProps } from "./LinkIcon";

const platformToIconMap = new Map<string, any>();
platformToIconMap.set("Facebook", FacebookIcon);
platformToIconMap.set("Twitter", TwitterIcon);
platformToIconMap.set("Instagram", InstagramIcon);
platformToIconMap.set("Linkedin", LinkedInIcon);
platformToIconMap.set("Github", GitHubIcon);
platformToIconMap.set("Slack", SlackIcon);

type SocialMediaPlatform =
| "Facebook"
| "Github"
| "Instagram"
| "LinkedIn"
| "Slack"
| "Twitter";

interface SocialMediaLink {
platform: SocialMediaPlatform;
// TODO(koech): Confirm why we chose url instead of href in the CMS
url: string;
}

interface SocialMediaLinkIconProps extends Omit<LinkIconProps, "href"> {
platform: SocialMediaPlatform;
url: string;
}

const SocialMediaLinkIcon = React.forwardRef(function SocialMediaLinkIcon(
{ IconProps, url, platform, ...props }: SocialMediaLinkIconProps,
ref: React.ForwardedRef<HTMLAnchorElement>,
) {
const Icon = platformToIconMap.get(platform);

if (!Icon) {
return null;
}
return (
<LinkIcon
{...props}
IconProps={{
component: Icon,
...IconProps,
}}
href={url}
/>
);
});

export type { SocialMediaLink, SocialMediaLinkIconProps, SocialMediaPlatform };
export default SocialMediaLinkIcon;
9 changes: 9 additions & 0 deletions apps/roboshield/src/components/SocialMediaLinkIcon/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import type {
SocialMediaLink,
SocialMediaLinkIconProps,
SocialMediaPlatform,
} from "./SocialMediaLinkIcon";
import SocialMediaLinkIcon from "./SocialMediaLinkIcon";

export type { SocialMediaLink, SocialMediaLinkIconProps, SocialMediaPlatform };
export default SocialMediaLinkIcon;
45 changes: 14 additions & 31 deletions apps/roboshield/src/components/StayInTouch/StayInTouch.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,11 @@ import { Link, RichTypography } from "@commons-ui/next";
import { Grid, SvgIcon } from "@mui/material";
import React from "react";

import FacebookIcon from "@/roboshield/assets/icons/Type=facebook, Size=24, Color=CurrentColor.svg";
import GitHubIcon from "@/roboshield/assets/icons/Type=github, Size=24, Color=CurrentColor.svg";
import InstagramIcon from "@/roboshield/assets/icons/Type=instagram, Size=24, Color=CurrentColor.svg";
import LinkedInIcon from "@/roboshield/assets/icons/Type=linkedin, Size=24, Color=CurrentColor.svg";
import SlackIcon from "@/roboshield/assets/icons/Type=slack, Size=24, Color=CurrentColor.svg";
import TwitterIcon from "@/roboshield/assets/icons/Type=twitter, Size=24, Color=CurrentColor.svg";

const platformToIconMap = new Map<string, any>();
platformToIconMap.set("Facebook", FacebookIcon);
platformToIconMap.set("Twitter", TwitterIcon);
platformToIconMap.set("Instagram", InstagramIcon);
platformToIconMap.set("Linkedin", LinkedInIcon);
platformToIconMap.set("Github", GitHubIcon);
platformToIconMap.set("Slack", SlackIcon);
import SocialMediaLinkIcon from "@/roboshield/components/SocialMediaLinkIcon";
import type { SocialMediaLink } from "@/roboshield/components/SocialMediaLinkIcon";

interface StayInTouchProps {
links: { url: string; platform: string }[];
links: SocialMediaLink[];
sx: any;
title: string;
}
Expand Down Expand Up @@ -60,11 +48,6 @@ const StayInTouch = React.forwardRef(function StayInTouch(
justifyContent={{ xs: "center", md: "flex-start" }}
>
{links.map(({ url, platform }) => {
const Icon = platformToIconMap.get(platform);

if (!(Icon || url)) {
return null;
}
return (
<Grid
item
Expand All @@ -76,20 +59,20 @@ const StayInTouch = React.forwardRef(function StayInTouch(
},
}}
>
<Link
<SocialMediaLinkIcon
color="inherit"
url={url}
platform={platform}
IconProps={{
fontSize: "inherit",
sx: {
fill: { xs: "none" },
},
}}
sx={{
display: "block",
}}
color="inherit"
href={url}
>
<SvgIcon
component={Icon}
sx={{
fill: { xs: "none" },
}}
/>
</Link>
/>
</Grid>
);
})}
Expand Down

0 comments on commit 2e4999d

Please sign in to comment.