Files
twenty/packages/twenty-front/src/modules/ui/navigation/navigation-drawer/components/NavigationDrawerSectionTitle.tsx
nitin c63842925f Favorites Folders Fast Followups (#8920)
Fixes :
<img width="716" alt="Screenshot 2024-12-06 at 3 45 41 PM"
src="https://github.com/user-attachments/assets/61fdf355-0d0a-4ed7-befa-ada23341a58f">

Fixes: Reduce menu width to 160px and it should appear below three dots
<img width="394" alt="Screenshot 2024-12-06 at 3 46 49 PM"
src="https://github.com/user-attachments/assets/b1266f83-9b6f-445b-9409-d7f691776bd0">

Fixes: The right margin should be 2px
<img width="1134" alt="Screenshot 2024-12-06 at 3 47 45 PM"
src="https://github.com/user-attachments/assets/b6dd857c-6575-418d-8e32-64cd4e5d4e85">

Fixes:
Requirement: Clicking the heart Icon should put the record as favorite.
It shouldn't open the menu on first click. It should only on second
click, when the record is already a favorite.

---------

Co-authored-by: Charles Bochet <charles@twenty.com>
2024-12-17 12:15:36 +01:00

87 lines
2.7 KiB
TypeScript

import { currentUserState } from '@/auth/states/currentUserState';
import { useIsSettingsPage } from '@/navigation/hooks/useIsSettingsPage';
import { useIsPrefetchLoading } from '@/prefetch/hooks/useIsPrefetchLoading';
import { NavigationDrawerSectionTitleSkeletonLoader } from '@/ui/navigation/navigation-drawer/components/NavigationDrawerSectionTitleSkeletonLoader';
import { isNavigationDrawerExpandedState } from '@/ui/navigation/states/isNavigationDrawerExpanded';
import { useIsMobile } from '@/ui/utilities/responsive/hooks/useIsMobile';
import styled from '@emotion/styled';
import React from 'react';
import { useRecoilValue } from 'recoil';
import { isDefined } from 'twenty-ui';
const StyledTitle = styled.div`
align-items: center;
border-radius: ${({ theme }) => theme.border.radius.sm};
color: ${({ theme }) => theme.font.color.light};
display: flex;
font-size: ${({ theme }) => theme.font.size.xs};
font-weight: ${({ theme }) => theme.font.weight.semiBold};
height: ${({ theme }) => theme.spacing(5)};
padding-left: ${({ theme }) => theme.spacing(1)};
padding-right: ${({ theme }) => theme.spacing(0.5)};
padding-top: ${({ theme }) => theme.spacing(1)};
padding-bottom: ${({ theme }) => theme.spacing(1)};
justify-content: space-between;
&:hover {
cursor: pointer;
background-color: ${({ theme }) => theme.background.transparent.light};
}
`;
const StyledLabel = styled.div`
flex-grow: 1;
`;
type StyledRightIconProps = {
isMobile: boolean;
};
const StyledRightIcon = styled.div<StyledRightIconProps>`
cursor: pointer;
opacity: ${({ isMobile }) => (isMobile ? 1 : 0)};
.section-title-container:hover & {
opacity: 1;
}
`;
type NavigationDrawerSectionTitleProps = {
onClick?: () => void;
label: string;
rightIcon?: React.ReactNode;
};
export const NavigationDrawerSectionTitle = ({
onClick,
label,
rightIcon,
}: NavigationDrawerSectionTitleProps) => {
const isMobile = useIsMobile();
const isNavigationDrawerExpanded = useRecoilValue(
isNavigationDrawerExpandedState,
);
const isSettingsPage = useIsSettingsPage();
const currentUser = useRecoilValue(currentUserState);
const loading = useIsPrefetchLoading();
const handleTitleClick = (e: React.MouseEvent<HTMLDivElement>) => {
e.stopPropagation();
if (isDefined(onClick) && (isNavigationDrawerExpanded || isSettingsPage)) {
onClick();
}
};
if (loading && isDefined(currentUser)) {
return <NavigationDrawerSectionTitleSkeletonLoader />;
}
return (
<StyledTitle className="section-title-container">
<StyledLabel onClick={handleTitleClick}>{label}</StyledLabel>
{rightIcon && (
<StyledRightIcon isMobile={isMobile}>{rightIcon}</StyledRightIcon>
)}
</StyledTitle>
);
};