Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue 546 - Adicionar ícone de erro no accordion #584

Merged
merged 18 commits into from
Aug 19, 2024
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
ba8019f
feat: icon error in SocialAccordion if have invalid account
jorge933 Aug 12, 2024
f56d550
feat: red background and color in AccountCard
jorge933 Aug 12, 2024
712e679
Merge branch 'master' into issue-546
aalmeida00 Aug 12, 2024
f6188b7
refactor: removed unused property in Switch.types
jorge933 Aug 13, 2024
f6e651c
refactor: condition removed in Switch onChange
jorge933 Aug 13, 2024
8ed6c20
refactor: false as default value in validation property in AccountCard
jorge933 Aug 13, 2024
2271868
refactor: number of accounts appearing in Social Accordion even if th…
jorge933 Aug 13, 2024
1674941
feat: component AccountQuantity to show number of accounts in SocialA…
jorge933 Aug 13, 2024
d50ad8c
refactor: do not show the number of accounts on SocialAccordion if yo…
jorge933 Aug 14, 2024
bca7bda
refactor: all accounts true in useSocialMediaStore.mock
jorge933 Aug 14, 2024
0cc69ae
revert: reverted commit all accounts true in useSocialMediaStore.mock
jorge933 Aug 16, 2024
a300882
feat: setting valid as true in reduce on useSocialMediaStore
jorge933 Aug 16, 2024
c743e67
refactor: invalid prop as optional in AccountCard.types
jorge933 Aug 16, 2024
c27bd25
refactor: reduce extracted to a variable in SocialAccordion
jorge933 Aug 16, 2024
e110573
Merge branch 'master' into issue-546
juliaam Aug 16, 2024
da9bd52
unnecessary keys removed in SocialAccordion
jorge933 Aug 16, 2024
5630c22
refactor: classNames of AccountCard extracted to variable
jorge933 Aug 19, 2024
7b1d14e
style: prettier formatting in AccountCard
jorge933 Aug 19, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
11 changes: 10 additions & 1 deletion src/components/AccountCard/AccountCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export function AccountCard({
avatarURL,
className,
hasError = false,
invalid = false,
isEnabled = false,
isFavorited = false,
onEnableChange,
Expand All @@ -34,7 +35,14 @@ export function AccountCard({
};

return (
<div className={classNames(scss.container, className)} {...props}>
<div
className={classNames({
className,
[scss.container]: true,
[scss.invalid]: invalid,
})}
{...props}
>
<Avatar className={scss.avatar} image={avatarURL} username={username} />
<p className={scss.username}>{username}</p>
<Button
Expand All @@ -46,6 +54,7 @@ export function AccountCard({
/>
<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
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 Down Expand Up @@ -69,9 +71,12 @@ function SocialAccordion(props: SocialAccordionProps): ReactNode {
</div>
{props.error && renderError()}
<div className={scss.accordionInfo}>
<span className={scss.accountQuantity}>
{props.accounts.length}+
</span>
{props.accounts.some(({ valid }) => !valid) ? (
<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;
};
Loading