Skip to content

Commit

Permalink
Merge pull request #316 from AppQuality/profile-modal-notifications
Browse files Browse the repository at this point in the history
Profile modal notifications
  • Loading branch information
marcbon authored Feb 21, 2024
2 parents 9948076 + 8aa219a commit 8345e4f
Show file tree
Hide file tree
Showing 11 changed files with 222 additions and 55 deletions.
3 changes: 3 additions & 0 deletions src/assets/icons/gear-fill.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
18 changes: 17 additions & 1 deletion src/stories/profile-modal/_types.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { LiHTMLAttributes } from "react";
import { InputHTMLAttributes, LiHTMLAttributes } from "react";
import { NextItemArgs } from "../dropdowns/menu/_types";
import { ModalArgs } from "../modals/_types";

Expand Down Expand Up @@ -50,4 +50,20 @@ export interface UserMenuArgs extends LiHTMLAttributes<HTMLLIElement> {
onLogout: () => void;
onCopyEmail?: () => void;
chatSupport?: boolean;
settingValue?: number;
i18n?: {
settingsTitle?: string;
settingsIntroText?: string;
settingsOutroText?: {
paragraph_1: string;
paragraph_2?: string;
paragraph_3?: string;
};
settingsToggle?: {
title: string;
on: string;
off: string;
};
};
onSetSettings: (value: number) => void;
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import styled from "styled-components";
import { Avatar } from "../avatar";
import { theme } from "../theme";
import { flexColumnCenter } from "../theme/mixins";
import { MD, SM } from "../typography/typescale";
import { getInitials } from "./utils";
import { UserProfileProps } from "./_types";
import { Avatar } from "../../avatar";
import { theme } from "../../theme";
import { flexColumnCenter } from "../../theme/mixins";
import { MD, SM } from "../../typography/typescale";
import { getInitials } from "../utils";
import { UserProfileProps } from "../_types";
import { retrieveComponentStyles } from "@zendeskgarden/react-theming";

const ProfileContainer = styled.div`
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import styled from "styled-components";
import { MenuItemIcon, StyledMenuItemIcon } from "./menuItemIcon";
import { flexCenter, flexStart } from "../theme/mixins";
import { flexCenter, flexStart } from "../../theme/mixins";

import { theme } from "../theme";
import { MenuItemProps } from "./_types";
import { getColor } from "../theme/utils";
import { theme } from "../../theme";
import { MenuItemProps } from "../_types";
import { getColor } from "../../theme/utils";

export interface IStyledItemProps {
isFocused?: boolean;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import styled from "styled-components";
import { theme } from "../theme";
import { theme } from "../../theme";

import { ReactComponent as ChevronIcon } from "../../assets/icons/chevron-right-stroke.svg";
import { ReactComponent as ChevronIcon } from "../../../assets/icons/chevron-right-stroke.svg";

interface IStyledItemIconProps {
isCompact?: boolean;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ReactComponent as ChevronIcon } from "../../assets/icons/chevron-left-stroke.svg";
import { Button } from "../buttons/button";
import { ReactComponent as ChevronIcon } from "../../../assets/icons/chevron-left-stroke.svg";
import { Button } from "../../buttons/button";
import styled from "styled-components";
import { ButtonArgs } from "../buttons/button/_types";
import { ButtonArgs } from "../../buttons/button/_types";

const StyledButton = styled(Button)`
color: ${(props) => props.theme.palette.grey[800]};
Expand Down
30 changes: 23 additions & 7 deletions src/stories/profile-modal/index.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import { ComponentMeta, Story } from "@storybook/react";
import { Col } from "../grid/col";
import { Row } from "../grid/row";

import { ProfileModalArgs, UserMenuArgs } from "./_types";
import { ProfileModal } from ".";
import { ToastProvider, useToast, Notification } from "../notifications";
import { Notification, ToastProvider, useToast } from "../notifications";
import { ProfileModalArgs, UserMenuArgs } from "./_types";

const languages = {
en: {
Expand All @@ -28,12 +28,8 @@ const csm = {
// picture: "https://placeimg.com/300/300/animal",
};

const ProfileModalComponent = ({
menuArgs,
...args
}: ProfileModalArgs) => {
const ProfileModalComponent = ({ menuArgs, ...args }: ProfileModalArgs) => {
const { addToast } = useToast();

return (
<ProfileModal
{...args}
Expand Down Expand Up @@ -100,6 +96,26 @@ const defaultArgs: UserMenuArgs = {
onCopyEmail: () => {
alert("Copied to clipboard!");
},
i18n: {
settingsTitle: "Notifications settings",
settingsIntroText: "Manage the notifications we send you by email.",
settingsOutroText: {
paragraph_1: "By turning on notifications, you will be updated on:",
paragraph_2:
"a comment, a campaign starting, a campaign ending, a mention and an invitation",
paragraph_3:
"By turning off notifications, you will be only updated on mentions and invitations.",
},
settingsToggle: {
title: "Allow notifications",
on: "Yes",
off: "No",
},
},
settingValue: 0,
onSetSettings: (value: number) => {
alert(value === 1 ? "Notifications enabled" : "Notifications disabled");
},
};

export const Default = Template.bind({});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
import { MenuItem } from "./menuItem";
import { ReactComponent as QuestionMark } from "../../assets/icons/question-mark.svg";
import { ReactComponent as CopyIcon } from "../../assets/icons/copy.svg";
import { ReactComponent as InfoFill } from "../../assets/icons/info-fill.svg";
import { PreviousButton } from "./previousMenuButton";
import { Separator } from "../dropdowns/menu";
import { Paragraph } from "../typography/paragraph";
import { MD, SM } from "../typography/typescale";
import { Avatar } from "../avatar";
import { MenuItem } from "../components/menuItem";
import { ReactComponent as QuestionMark } from "../../../assets/icons/question-mark.svg";
import { ReactComponent as CopyIcon } from "../../../assets/icons/copy.svg";
import { ReactComponent as InfoFill } from "../../../assets/icons/info-fill.svg";
import { PreviousButton } from "../components/previousMenuButton";
import { Separator } from "../../dropdowns/menu";
import { Paragraph } from "../../typography/paragraph";
import { MD, SM } from "../../typography/typescale";
import { Avatar } from "../../avatar";
import styled from "styled-components";
import { theme } from "../theme";
import { flexCenter } from "../theme/mixins";
import { Button } from "../buttons/button";
import { Anchor } from "../buttons/anchor";
import { MenuItemProps } from "./_types";
import { getInitials } from "./utils";
import { getColor } from "../theme/utils";
import { theme } from "../../theme";
import { flexCenter } from "../../theme/mixins";
import { Button } from "../../buttons/button";
import { Anchor } from "../../buttons/anchor";
import { MenuItemProps } from "../_types";
import { getInitials } from "../utils";
import { getColor } from "../../theme/utils";

interface HelpItemProps extends MenuItemProps {
title: string;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import { MenuItem, MenuItemBody } from "./menuItem";
import { MenuItem, MenuItemBody } from "../components/menuItem";

import { ReactComponent as CheckIcon } from "../../assets/icons/check-lg.svg";
import { ReactComponent as EmptyIcon } from "../../assets/icons/empty.svg";
import { ReactComponent as TranslationIcon } from "../../assets/icons/translation-exists.svg";
import { PreviousButton } from "./previousMenuButton";
import { Separator } from "../dropdowns/menu";
import { MD } from "../typography/typescale";
import { ReactComponent as CheckIcon } from "../../../assets/icons/check-lg.svg";
import { ReactComponent as EmptyIcon } from "../../../assets/icons/empty.svg";
import { ReactComponent as TranslationIcon } from "../../../assets/icons/translation-exists.svg";
import { PreviousButton } from "../components/previousMenuButton";
import { Separator } from "../../dropdowns/menu";
import { MD } from "../../typography/typescale";
import styled from "styled-components";
import { theme } from "../theme";
import { flexStart } from "../theme/mixins";
import { Button } from "../buttons/button";
import { Language, MenuItemProps } from "./_types";
import { Span } from "../typography/span";
import { theme } from "../../theme";
import { flexStart } from "../../theme/mixins";
import { Button } from "../../buttons/button";
import { Language, MenuItemProps } from "../_types";
import { Span } from "../../typography/span";

interface LanguagesProps extends MenuItemProps {
title: string;
Expand Down
118 changes: 118 additions & 0 deletions src/stories/profile-modal/items/settingsMenuItem.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
import { Paragraph } from "@zendeskgarden/react-notifications";
import { MenuItemProps } from "../_types";
import { PreviousButton } from "../components/previousMenuButton";
import { ReactComponent as GearIcon } from "../../../assets/icons/gear-fill.svg";
import styled from "styled-components";
import { Separator } from "../../dropdowns/menu";
import { Toggle } from "../../forms/toggle";
import { MenuItem } from "../components/menuItem";
import { theme } from "../../theme";
import { Field } from "../../forms/field";
import { Label } from "../../label";
import { useState } from "react";
import { MD, SM } from "../../typography/typescale";

interface SettingsProps extends MenuItemProps {
settingValue?: number;

onSetSettings?: (value: number) => void;
i18n?: {
settingsTitle?: string;
settingsIntroText?: string;
settingsOutroText?: {
paragraph_1?: string;
paragraph_2?: string;
paragraph_3?: string;
};
settingsToggle?: {
title: string;
on: string;
off: string;
};
};
}

const StyledBody = styled.div`
margin: ${({ theme }) => theme.space.base * 6}px
${({ theme }) => theme.space.base * 4}px;
`;

const TriggerTitle = styled(MD)`
color: ${({ theme }) => theme.palette.blue[700]};
margin-bottom: ${({ theme }) => theme.space.xs};
`;

const SettingsIntroText = styled(Paragraph)`
margin-bottom: ${({ theme }) => theme.space.md};
`;

const SettingsOutroText = styled(Paragraph)`
display: flex;
flex-direction: column;
margin-top: ${({ theme }) => theme.space.md};
`;

export const SettingsItem = (props: SettingsProps) => {
const [value, setValue] = useState(props.settingValue || 0);

const onToggleSettings = (value: number) => {
setValue(value);
props.onSetSettings && props.onSetSettings(value);
};

const content = (
<>
<PreviousButton onClick={() => props.setActive("")} isBasic>
{props.i18n?.settingsTitle ?? "Notifications Settings"}
</PreviousButton>
<Separator />
<StyledBody>
{props.i18n && props.i18n.settingsIntroText && (
<SettingsIntroText>
<SM>{props.i18n.settingsIntroText}</SM>
</SettingsIntroText>
)}
<Field>
<TriggerTitle isBold>
{props.i18n?.settingsToggle?.title ?? "Allow notifications"}
</TriggerTitle>
<Toggle
checked={value === 1}
onChange={() => onToggleSettings(value === 1 ? 0 : 1)}
>
<Label>
{value === 1
? props.i18n?.settingsToggle?.on ?? "Yes"
: props.i18n?.settingsToggle?.off ?? "No"}
</Label>
</Toggle>
</Field>
{props.i18n && props.i18n.settingsOutroText && (
<>
<SettingsOutroText>
<SM>{props.i18n.settingsOutroText.paragraph_1}</SM>
<SM>{props.i18n.settingsOutroText.paragraph_2}</SM>
</SettingsOutroText>
<SettingsOutroText>
<SM>{props.i18n.settingsOutroText.paragraph_3}</SM>
</SettingsOutroText>
</>
)}
</StyledBody>
</>
);

return (
<>
<MenuItem
content={content}
value={props.value}
selectedItem={props.selectedItem}
setActive={props.setActive}
icon={<GearIcon color={theme.palette.blue[600]} />}
>
{props.title}
</MenuItem>
</>
);
};
22 changes: 18 additions & 4 deletions src/stories/profile-modal/userMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@ import { UserMenuArgs } from "./_types";
import { ReactComponent as ExitIcon } from "../../assets/icons/exit.svg";
import { ReactComponent as ThumbsUp } from "../../assets/icons/thumbs-up.svg";
import { ReactComponent as LockIcon } from "../../assets/icons/lock-locked-fill.svg";
import { MenuItem, MenuItemBody } from "./menuItem";
import { MenuItem, MenuItemBody } from "./components/menuItem";
import styled from "styled-components";
import { HelpItem } from "./helpMenuItem";
import { LanguageItem } from "./languageMenuItem";
import { HelpItem } from "./items/helpMenuItem";
import { LanguageItem } from "./items/languageMenuItem";
import { theme } from "../theme";
import { Separator } from "../dropdowns/menu";
import { MD } from "../typography/typescale";
import { UserContainer } from "./UserContainer";
import { UserContainer } from "./components/UserContainer";
import { SettingsItem } from "./items/settingsMenuItem";

const StyledList = styled.ul`
padding: 0;
Expand Down Expand Up @@ -61,6 +62,19 @@ export const UserMenu = (props: UserMenuArgs) => {
onCopyEmail={props?.onCopyEmail}
chatSupport={props?.chatSupport}
/>
<SettingsItem
value={"settings"}
selectedItem={item}
setActive={(i) => toggleItem(i)}
title={props.i18n?.settingsTitle || "Notifications Settings"}
settingValue={props.settingValue}
i18n={{
settingsIntroText: props.i18n?.settingsIntroText,
settingsOutroText: props.i18n?.settingsOutroText,
settingsToggle: props.i18n?.settingsToggle,
}}
onSetSettings={props.onSetSettings}
/>
<LanguageItem
title={props.languageTitle || "Change Language"}
value={"language-selector"}
Expand Down

0 comments on commit 8345e4f

Please sign in to comment.