Skip to content

Commit

Permalink
Merge branch 'devhatt:master' into refactorInputMedia/#542
Browse files Browse the repository at this point in the history
  • Loading branch information
JpBurgarelli authored Aug 22, 2024
2 parents 7f7761b + 893a84e commit e3a62be
Show file tree
Hide file tree
Showing 18 changed files with 71 additions and 22 deletions.
15 changes: 6 additions & 9 deletions src/components/AccordionTab/AccordionTab.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,8 @@
display: none;

color: $primaryWhite;
font-size: 4rem;
font-weight: 900;

margin-right: 2rem;
margin-top: 0.2rem;

cursor: pointer;
}
Expand Down Expand Up @@ -57,19 +55,18 @@
font-size: 1.6rem;
line-height: 1;

padding: 1.2rem;
padding: 1.3rem 2.2rem;

position: relative;

background-color: $secondaryPurple;
border-radius: 17px 17px 0 0;

&::before {
font-size: 1.8rem;
.innerHeader {
display: flex;
gap: 1.5rem;

margin-right: 1rem;

content: '';
align-items: center;
}
}

Expand Down
8 changes: 5 additions & 3 deletions src/components/AccordionTab/AccordionTab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,18 @@ function AccordionTab({
const handleClose = (): void => {
if (props.onChangeOpen) props.onChangeOpen(!isOpen);
};

const renderCloseButton = (): ReactNode => (
<button className={scss.closeButton} onClick={handleClose} type="button">
<Icon icon="minus" size={16} />
<Icon icon={isOpen ? 'minus' : 'plus'} size={16} />
</button>
);

const renderHeader = (): ReactNode => (
<div className={scss.header}>
<p className={scss.headerTitle}>{props.title}</p>
<div className={scss.innerHeader}>
<Icon icon="circle" size={12} />
<p className={scss.headerTitle}>{props.title}</p>
</div>
{hideCloseButton ? null : renderCloseButton()}
</div>
);
Expand Down
4 changes: 4 additions & 0 deletions src/components/AccountCard/AccountCard.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@
border-bottom: 0.1rem solid $primaryGray;

background-color: $secondaryWhite;

&.invalid {
background-color: $primaryRed;
}
}

.username {
Expand Down
2 changes: 1 addition & 1 deletion src/components/AccountCard/AccountCard.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const makeSut = ({
username = faker.internet.userName(),
...props
}: Partial<AccountCardProps>): RenderResult =>
render(<AccountCard username={username} {...props} />);
render(<AccountCard invalid={false} username={username} {...props} />);

describe('AccountCard', () => {
let user = userEvent.setup();
Expand Down
10 changes: 9 additions & 1 deletion src/components/AccountCard/AccountCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export function AccountCard({
avatarURL,
className,
hasError = false,
invalid = false,
isEnabled = false,
isFavorited = false,
onEnableChange,
Expand All @@ -31,13 +32,20 @@ export function AccountCard({
if (onEnableChange) onEnableChange(!enabled);
};

const accountCardClassNames = classNames({
className,
[scss.container]: true,
[scss.invalid]: invalid,
});

return (
<div className={classNames(scss.container, className)} {...props}>
<div className={accountCardClassNames} {...props}>
<Avatar className={scss.avatar} image={avatarURL} username={username} />
<p className={scss.username}>{username}</p>
<button className={scss.star} onClick={handleFavoriteChange} />
<Switch
checked={enabled}
invalid={invalid}
onChange={handleEnableChange}
variant={hasError ? 'error' : 'default'}
/>
Expand Down
1 change: 1 addition & 0 deletions src/components/AccountCard/AccountCard.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export type AccountCardProps = BaseAccountCardProps & {
avatarURL?: string;
hasError?: boolean;
icon?: string;
invalid?: boolean;
isEnabled?: boolean;
isFavorited?: boolean;
onEnableChange?: (isEnabled: boolean) => void;
Expand Down
2 changes: 2 additions & 0 deletions src/components/Icon/data.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import Alert from './icons/alert.svg?react';
import ArrowRight from './icons/arrow-right.svg?react';
import Check from './icons/check.svg?react';
import Circle from './icons/circle.svg?react';
import Close from './icons/close.svg?react';
import TriangleDropArrow from './icons/drop-down.svg?react';
import Hamburguer from './icons/hamburguer.svg?react';
Expand All @@ -18,6 +19,7 @@ export const icons = {
alert: Alert,
'arrow-right': ArrowRight,
check: Check,
circle: Circle,
close: Close,
hamburguer: Hamburguer,
'left-arrow': LeftArrow,
Expand Down
3 changes: 3 additions & 0 deletions src/components/Icon/icons/circle.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions src/components/Switch/Switch.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@
scale: 0.85;
}

&.invalid {
color: $secondaryRed;
}

&:active::before {
transform: scale(0.8);
}
Expand Down
3 changes: 2 additions & 1 deletion src/components/Switch/Switch.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@ import scss from './Switch.module.scss';
import { SwitchProps } from './Switch.types';

export const Switch = forwardRef<HTMLInputElement, SwitchProps>(
({ variant = 'default', ...props }, ref) => {
({ invalid, variant = 'default', ...props }, ref) => {
const handleChange = (event: ChangeEvent<HTMLInputElement>): void => {
if (props.onChange) props.onChange(event.target.checked);
};

const classes = classNames(scss.input, {
[scss.error]: variant === 'error',
[scss.invalid]: invalid,
});

return (
Expand Down
1 change: 1 addition & 0 deletions src/components/Switch/Switch.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export type BaseSwitchProps = Omit<ComponentPropsWithRef<'input'>, 'onChange'>;

export type SwitchProps = BaseSwitchProps & {
checked?: boolean;
invalid?: boolean;
onChange?: (checked: boolean) => void;
variant?: 'default' | 'error';
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { ReactNode } from 'react';

import scss from './SocialAccordion.module.scss';

import { AccountQuantityProps } from './SocialAccordion.type';

export function AccountQuantity({
accountQuantity,
}: AccountQuantityProps): ReactNode {
return <span className={scss.accountQuantity}>{accountQuantity}+</span>;
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@
border: 1px solid $primaryGray;

cursor: pointer;

.alertIcon {
color: $secondaryRed;
}
}

.socialInfo {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ describe('SocialAccordion', () => {

render(
<SocialAccordion
accounts={[account]}
accounts={[{ ...account, valid: true }]}
error={false}
socialMediaId="DISCORD_EXAMPLE_ID"
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import scss from './SocialAccordion.module.scss';

import iconPlaceholderForIcon from './assets/facebook.svg';

import { AccountQuantity } from './SocialAccordion.components';
import { SocialAccordionProps } from './SocialAccordion.type';

function SocialAccordion(props: SocialAccordionProps): ReactNode {
Expand All @@ -35,6 +36,7 @@ function SocialAccordion(props: SocialAccordionProps): ReactNode {
<li key={account.id}>
<AccountCard
avatarURL={account.avatar}
invalid={!account.valid}
isEnabled={account.valid}
onEnableChange={(enable) => activateSocialTab(enable, account)}
username={account.userName}
Expand All @@ -46,6 +48,8 @@ function SocialAccordion(props: SocialAccordionProps): ReactNode {
<ul role="listitem">{renderAccordionMap()}</ul>
);

const hasInvalidAccount = props.accounts.some(({ valid }) => !valid);

return (
<Accordion
className={scss.wrapper}
Expand All @@ -69,9 +73,12 @@ function SocialAccordion(props: SocialAccordionProps): ReactNode {
</div>
{props.error && renderError()}
<div className={scss.accordionInfo}>
<span className={scss.accountQuantity}>
{props.accounts.length}+
</span>
{hasInvalidAccount ? (
<Icon className={scss.alertIcon} icon="alert" size={16} />
) : (
<AccountQuantity accountQuantity={props.accounts.length} />
)}

<Icon
aria-label={
isOpen ? 'Accordion is open' : 'Accordion is closed'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,7 @@ export type IAccountList = {
socialMediaName?: string;
username: string;
};

export type AccountQuantityProps = {
accountQuantity: number;
};
4 changes: 2 additions & 2 deletions src/stores/useSocialMediaStore/useSocialMediaStore.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ describe('useSocialMediaStore', () => {
socialMediaId: 'DISCORD_EXAMPLE_ID',
token: 'DISCORD_EXAMPLE_TOKEN_1',
userName: 'Discord User 1',
valid: false,
valid: true,
},
],
TWITTER_EXAMPLE_ID: [
Expand All @@ -115,7 +115,7 @@ describe('useSocialMediaStore', () => {
socialMediaId: 'TWITTER_EXAMPLE_ID',
token: 'TWITTER_EXAMPLE_TOKEN_14',
userName: 'Twitter User 14',
valid: false,
valid: true,
},
],
};
Expand Down
2 changes: 1 addition & 1 deletion src/stores/useSocialMediaStore/useSocialMediaStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export const useSocialMediaStore = create<SocialMediaState>((set) => ({
...(agg[account.socialMediaId] ?? []),
{
...account,
valid: false,
valid: true,
},
],
}),
Expand Down

0 comments on commit e3a62be

Please sign in to comment.