mirror of
https://github.com/Unleash/unleash.git
synced 2025-02-04 00:18:01 +01:00
refactor: project archive card (#7859)
- Refactored "favorites" action, and fixed issue with "favorite" prop - Refactored "owners" - simplified footer
This commit is contained in:
parent
9f0fd7e200
commit
ccb29a5acf
@ -12,9 +12,9 @@ import {
|
|||||||
} from './NewProjectCard.styles';
|
} from './NewProjectCard.styles';
|
||||||
import { ProjectCardFooter } from './ProjectCardFooter/ProjectCardFooter';
|
import { ProjectCardFooter } from './ProjectCardFooter/ProjectCardFooter';
|
||||||
import { ProjectModeBadge } from './ProjectModeBadge/ProjectModeBadge';
|
import { ProjectModeBadge } from './ProjectModeBadge/ProjectModeBadge';
|
||||||
import { ProjectOwners } from './ProjectOwners/ProjectOwners';
|
|
||||||
import type { ProjectSchemaOwners } from 'openapi';
|
import type { ProjectSchemaOwners } from 'openapi';
|
||||||
import { ProjectIcon } from 'component/common/ProjectIcon/ProjectIcon';
|
import { ProjectIcon } from 'component/common/ProjectIcon/ProjectIcon';
|
||||||
|
import { FavoriteAction } from './ProjectCardFooter/FavoriteAction/FavoriteAction';
|
||||||
|
|
||||||
interface IProjectCardProps {
|
interface IProjectCardProps {
|
||||||
name: string;
|
name: string;
|
||||||
@ -23,7 +23,7 @@ interface IProjectCardProps {
|
|||||||
memberCount?: number;
|
memberCount?: number;
|
||||||
id: string;
|
id: string;
|
||||||
onHover: () => void;
|
onHover: () => void;
|
||||||
isFavorite?: boolean;
|
favorite?: boolean;
|
||||||
mode: string;
|
mode: string;
|
||||||
owners?: ProjectSchemaOwners;
|
owners?: ProjectSchemaOwners;
|
||||||
}
|
}
|
||||||
@ -36,7 +36,7 @@ export const ProjectCard = ({
|
|||||||
onHover,
|
onHover,
|
||||||
id,
|
id,
|
||||||
mode,
|
mode,
|
||||||
isFavorite = false,
|
favorite = false,
|
||||||
owners,
|
owners,
|
||||||
}: IProjectCardProps) => (
|
}: IProjectCardProps) => (
|
||||||
<StyledProjectCard onMouseEnter={onHover}>
|
<StyledProjectCard onMouseEnter={onHover}>
|
||||||
@ -78,8 +78,8 @@ export const ProjectCard = ({
|
|||||||
</div>
|
</div>
|
||||||
</StyledDivInfo>
|
</StyledDivInfo>
|
||||||
</StyledProjectCardBody>
|
</StyledProjectCardBody>
|
||||||
<ProjectCardFooter id={id} isFavorite={isFavorite}>
|
<ProjectCardFooter id={id} owners={owners}>
|
||||||
<ProjectOwners owners={owners} />
|
<FavoriteAction id={id} isFavorite={favorite} />
|
||||||
</ProjectCardFooter>
|
</ProjectCardFooter>
|
||||||
</StyledProjectCard>
|
</StyledProjectCard>
|
||||||
);
|
);
|
||||||
|
@ -12,7 +12,6 @@ import {
|
|||||||
} from './NewProjectCard.styles';
|
} from './NewProjectCard.styles';
|
||||||
import { ProjectCardFooter } from './ProjectCardFooter/ProjectCardFooter';
|
import { ProjectCardFooter } from './ProjectCardFooter/ProjectCardFooter';
|
||||||
import { ProjectModeBadge } from './ProjectModeBadge/ProjectModeBadge';
|
import { ProjectModeBadge } from './ProjectModeBadge/ProjectModeBadge';
|
||||||
import { ProjectOwners } from './ProjectOwners/ProjectOwners';
|
|
||||||
import type { ProjectSchemaOwners } from 'openapi';
|
import type { ProjectSchemaOwners } from 'openapi';
|
||||||
import { ProjectIcon } from 'component/common/ProjectIcon/ProjectIcon';
|
import { ProjectIcon } from 'component/common/ProjectIcon/ProjectIcon';
|
||||||
import { formatDateYMDHM } from 'utils/formatDate';
|
import { formatDateYMDHM } from 'utils/formatDate';
|
||||||
@ -132,8 +131,13 @@ export const ProjectArchiveCard: FC<IProjectArchiveCardProps> = ({
|
|||||||
/>
|
/>
|
||||||
</StyledDivInfo>
|
</StyledDivInfo>
|
||||||
</StyledProjectCardBody>
|
</StyledProjectCardBody>
|
||||||
<ProjectCardFooter id={id} Actions={Actions} disabled>
|
<ProjectCardFooter
|
||||||
<ProjectOwners owners={owners} />
|
id={id}
|
||||||
|
Actions={Actions}
|
||||||
|
disabled
|
||||||
|
owners={owners}
|
||||||
|
>
|
||||||
|
<Actions id={id} />
|
||||||
</ProjectCardFooter>
|
</ProjectCardFooter>
|
||||||
</StyledProjectCard>
|
</StyledProjectCard>
|
||||||
);
|
);
|
||||||
|
@ -0,0 +1,40 @@
|
|||||||
|
import type { FC } from 'react';
|
||||||
|
import useToast from 'hooks/useToast';
|
||||||
|
import { useFavoriteProjectsApi } from 'hooks/api/actions/useFavoriteProjectsApi/useFavoriteProjectsApi';
|
||||||
|
import useProjects from 'hooks/api/getters/useProjects/useProjects';
|
||||||
|
import { styled } from '@mui/material';
|
||||||
|
import { FavoriteIconButton } from 'component/common/FavoriteIconButton/FavoriteIconButton';
|
||||||
|
|
||||||
|
type FavoriteActionProps = { id: string; isFavorite?: boolean };
|
||||||
|
|
||||||
|
const StyledFavoriteIconButton = styled(FavoriteIconButton)(({ theme }) => ({
|
||||||
|
margin: theme.spacing(1, 2, 0, 0),
|
||||||
|
}));
|
||||||
|
|
||||||
|
export const FavoriteAction: FC<FavoriteActionProps> = ({ id, isFavorite }) => {
|
||||||
|
const { setToastApiError } = useToast();
|
||||||
|
const { favorite, unfavorite } = useFavoriteProjectsApi();
|
||||||
|
const { refetch } = useProjects();
|
||||||
|
|
||||||
|
const onFavorite = async (e: React.SyntheticEvent) => {
|
||||||
|
e.preventDefault();
|
||||||
|
try {
|
||||||
|
if (isFavorite) {
|
||||||
|
await unfavorite(id);
|
||||||
|
} else {
|
||||||
|
await favorite(id);
|
||||||
|
}
|
||||||
|
refetch();
|
||||||
|
} catch (error) {
|
||||||
|
setToastApiError('Something went wrong, could not update favorite');
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<StyledFavoriteIconButton
|
||||||
|
onClick={onFavorite}
|
||||||
|
isFavorite={Boolean(isFavorite)}
|
||||||
|
size='medium'
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
};
|
@ -1,10 +1,10 @@
|
|||||||
import type React from 'react';
|
import type React from 'react';
|
||||||
import type { FC } from 'react';
|
import type { FC } from 'react';
|
||||||
import { Box, styled } from '@mui/material';
|
import { Box, styled } from '@mui/material';
|
||||||
import { FavoriteIconButton } from 'component/common/FavoriteIconButton/FavoriteIconButton';
|
import {
|
||||||
import useToast from 'hooks/useToast';
|
type IProjectOwnersProps,
|
||||||
import { useFavoriteProjectsApi } from 'hooks/api/actions/useFavoriteProjectsApi/useFavoriteProjectsApi';
|
ProjectOwners,
|
||||||
import useProjects from 'hooks/api/getters/useProjects/useProjects';
|
} from '../ProjectOwners/ProjectOwners';
|
||||||
|
|
||||||
interface IProjectCardFooterProps {
|
interface IProjectCardFooterProps {
|
||||||
id: string;
|
id: string;
|
||||||
@ -12,6 +12,7 @@ interface IProjectCardFooterProps {
|
|||||||
children?: React.ReactNode;
|
children?: React.ReactNode;
|
||||||
Actions?: FC<{ id: string; isFavorite?: boolean }>;
|
Actions?: FC<{ id: string; isFavorite?: boolean }>;
|
||||||
disabled?: boolean;
|
disabled?: boolean;
|
||||||
|
owners: IProjectOwnersProps['owners'];
|
||||||
}
|
}
|
||||||
|
|
||||||
const StyledFooter = styled(Box)<{ disabled: boolean }>(
|
const StyledFooter = styled(Box)<{ disabled: boolean }>(
|
||||||
@ -27,58 +28,15 @@ const StyledFooter = styled(Box)<{ disabled: boolean }>(
|
|||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
|
|
||||||
const StyledContainer = styled(Box)(({ theme }) => ({
|
|
||||||
padding: theme.spacing(1.5, 0, 2.5, 3),
|
|
||||||
display: 'flex',
|
|
||||||
alignItems: 'center',
|
|
||||||
}));
|
|
||||||
|
|
||||||
const StyledFavoriteIconButton = styled(FavoriteIconButton)(({ theme }) => ({
|
|
||||||
margin: theme.spacing(1, 2, 0, 0),
|
|
||||||
}));
|
|
||||||
|
|
||||||
const FavoriteAction: FC<{ id: string; isFavorite?: boolean }> = ({
|
|
||||||
id,
|
|
||||||
isFavorite,
|
|
||||||
}) => {
|
|
||||||
const { setToastApiError } = useToast();
|
|
||||||
const { favorite, unfavorite } = useFavoriteProjectsApi();
|
|
||||||
const { refetch } = useProjects();
|
|
||||||
|
|
||||||
const onFavorite = async (e: React.SyntheticEvent) => {
|
|
||||||
e.preventDefault();
|
|
||||||
try {
|
|
||||||
if (isFavorite) {
|
|
||||||
await unfavorite(id);
|
|
||||||
} else {
|
|
||||||
await favorite(id);
|
|
||||||
}
|
|
||||||
refetch();
|
|
||||||
} catch (error) {
|
|
||||||
setToastApiError('Something went wrong, could not update favorite');
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
return (
|
|
||||||
<StyledFavoriteIconButton
|
|
||||||
onClick={onFavorite}
|
|
||||||
isFavorite={Boolean(isFavorite)}
|
|
||||||
size='medium'
|
|
||||||
/>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
export const ProjectCardFooter: FC<IProjectCardFooterProps> = ({
|
export const ProjectCardFooter: FC<IProjectCardFooterProps> = ({
|
||||||
children,
|
children,
|
||||||
id,
|
owners,
|
||||||
isFavorite = false,
|
|
||||||
Actions = FavoriteAction,
|
|
||||||
disabled = false,
|
disabled = false,
|
||||||
}) => {
|
}) => {
|
||||||
return (
|
return (
|
||||||
<StyledFooter disabled={disabled}>
|
<StyledFooter disabled={disabled}>
|
||||||
<StyledContainer>{children}</StyledContainer>
|
<ProjectOwners owners={owners} />
|
||||||
<Actions id={id} isFavorite={isFavorite} />
|
{children}
|
||||||
</StyledFooter>
|
</StyledFooter>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
@ -5,7 +5,7 @@ import useUiConfig from 'hooks/api/getters/useUiConfig/useUiConfig';
|
|||||||
import { ConditionallyRender } from 'component/common/ConditionallyRender/ConditionallyRender';
|
import { ConditionallyRender } from 'component/common/ConditionallyRender/ConditionallyRender';
|
||||||
import { AvatarGroup } from 'component/common/AvatarGroup/AvatarGroup';
|
import { AvatarGroup } from 'component/common/AvatarGroup/AvatarGroup';
|
||||||
|
|
||||||
interface IProjectOwnersProps {
|
export interface IProjectOwnersProps {
|
||||||
owners?: ProjectSchema['owners'];
|
owners?: ProjectSchema['owners'];
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -59,12 +59,18 @@ const StyledHeader = styled('h3')(({ theme }) => ({
|
|||||||
fontWeight: theme.typography.fontWeightRegular,
|
fontWeight: theme.typography.fontWeightRegular,
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
const StyledWrapper = styled('div')(({ theme }) => ({
|
||||||
|
padding: theme.spacing(1.5, 0, 2.5, 3),
|
||||||
|
display: 'flex',
|
||||||
|
alignItems: 'center',
|
||||||
|
}));
|
||||||
|
|
||||||
export const ProjectOwners: FC<IProjectOwnersProps> = ({ owners = [] }) => {
|
export const ProjectOwners: FC<IProjectOwnersProps> = ({ owners = [] }) => {
|
||||||
const ownersMap = useOwnersMap();
|
const ownersMap = useOwnersMap();
|
||||||
const users = owners.map(ownersMap);
|
const users = owners.map(ownersMap);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<StyledWrapper>
|
||||||
<StyledContainer>
|
<StyledContainer>
|
||||||
<StyledHeader>
|
<StyledHeader>
|
||||||
{owners.length === 1 ? 'Owner' : 'Owners'}
|
{owners.length === 1 ? 'Owner' : 'Owners'}
|
||||||
@ -76,6 +82,6 @@ export const ProjectOwners: FC<IProjectOwnersProps> = ({ owners = [] }) => {
|
|||||||
show={<StyledUserName>{users[0]?.name}</StyledUserName>}
|
show={<StyledUserName>{users[0]?.name}</StyledUserName>}
|
||||||
elseShow={<div />}
|
elseShow={<div />}
|
||||||
/>
|
/>
|
||||||
</>
|
</StyledWrapper>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user