On Company Show, I can select an existing person and add it to the company (#1201)
* On Company Show, I can select an existing person and add it to the company Co-authored-by: Matheus <matheus_benini@hotmail.com> Co-authored-by: v1b3m <vibenjamin6@gmail.com> * Add requested changes Co-authored-by: v1b3m <vibenjamin6@gmail.com> Co-authored-by: Matheus <matheus_benini@hotmail.com> * Add excludePersonIds Co-authored-by: v1b3m <vibenjamin6@gmail.com> Co-authored-by: Matheus <matheus_benini@hotmail.com> * Add hotkey support * Fix popin placement and fix company show mobile * Fix popin placement and fix company show mobile --------- Co-authored-by: Matheus <matheus_benini@hotmail.com> Co-authored-by: v1b3m <vibenjamin6@gmail.com> Co-authored-by: Charles Bochet <charles@twenty.com>
This commit is contained in:
@ -35,11 +35,11 @@ const StyledTimelineContainer = styled.div`
|
|||||||
display: flex;
|
display: flex;
|
||||||
flex: 1 0 0;
|
flex: 1 0 0;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
gap: 4px;
|
gap: ${({ theme }) => theme.spacing(1)};
|
||||||
justify-content: flex-start;
|
justify-content: flex-start;
|
||||||
overflow-y: auto;
|
overflow-y: ${() => (useIsMobile() ? 'none' : 'auto')};
|
||||||
|
|
||||||
padding: 12px 16px 12px 16px;
|
padding: ${({ theme }) => theme.spacing(3)} ${({ theme }) => theme.spacing(4)};
|
||||||
`;
|
`;
|
||||||
|
|
||||||
const StyledTimelineEmptyContainer = styled.div`
|
const StyledTimelineEmptyContainer = styled.div`
|
||||||
@ -48,7 +48,7 @@ const StyledTimelineEmptyContainer = styled.div`
|
|||||||
display: flex;
|
display: flex;
|
||||||
flex: 1 0 0;
|
flex: 1 0 0;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
gap: 8px;
|
gap: ${({ theme }) => theme.spacing(2)};
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
`;
|
`;
|
||||||
|
|
||||||
@ -81,7 +81,7 @@ const StyledTopActionBar = styled.div`
|
|||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
left: 0px;
|
left: 0px;
|
||||||
padding: 12px 16px 12px 16px;
|
padding: 12px 16px 12px 16px;
|
||||||
position: sticky;
|
position: ${() => (useIsMobile() ? 'relative' : 'sticky')};
|
||||||
top: 0px;
|
top: 0px;
|
||||||
`;
|
`;
|
||||||
|
|
||||||
|
|||||||
@ -5,6 +5,7 @@ import { useCompleteTask } from '@/activities/hooks/useCompleteTask';
|
|||||||
import { useOpenActivityRightDrawer } from '@/activities/hooks/useOpenActivityRightDrawer';
|
import { useOpenActivityRightDrawer } from '@/activities/hooks/useOpenActivityRightDrawer';
|
||||||
import { IconNotes } from '@/ui/icon';
|
import { IconNotes } from '@/ui/icon';
|
||||||
import { OverflowingTextWithTooltip } from '@/ui/tooltip/OverflowingTextWithTooltip';
|
import { OverflowingTextWithTooltip } from '@/ui/tooltip/OverflowingTextWithTooltip';
|
||||||
|
import { useIsMobile } from '@/ui/utilities/responsive/hooks/useIsMobile';
|
||||||
import { Activity, User } from '~/generated/graphql';
|
import { Activity, User } from '~/generated/graphql';
|
||||||
import {
|
import {
|
||||||
beautifyExactDateTime,
|
beautifyExactDateTime,
|
||||||
@ -65,7 +66,9 @@ const StyledCardContainer = styled.div`
|
|||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
gap: ${({ theme }) => theme.spacing(2)};
|
gap: ${({ theme }) => theme.spacing(2)};
|
||||||
|
max-width: 100%;
|
||||||
padding: 4px 0px 20px 0px;
|
padding: 4px 0px 20px 0px;
|
||||||
|
width: ${() => (useIsMobile() ? '100%' : '400px')};
|
||||||
`;
|
`;
|
||||||
|
|
||||||
const StyledCard = styled.div`
|
const StyledCard = styled.div`
|
||||||
@ -76,9 +79,7 @@ const StyledCard = styled.div`
|
|||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
gap: ${({ theme }) => theme.spacing(3)};
|
gap: ${({ theme }) => theme.spacing(3)};
|
||||||
max-width: 100%;
|
width: calc(100% - ${({ theme }) => theme.spacing(4)});
|
||||||
position: relative;
|
|
||||||
width: 400px;
|
|
||||||
`;
|
`;
|
||||||
|
|
||||||
const StyledCardContent = styled.div`
|
const StyledCardContent = styled.div`
|
||||||
@ -105,14 +106,14 @@ const StyledTooltip = styled(Tooltip)`
|
|||||||
|
|
||||||
const StyledCardDetailsContainer = styled.div`
|
const StyledCardDetailsContainer = styled.div`
|
||||||
padding: ${({ theme }) => theme.spacing(2)};
|
padding: ${({ theme }) => theme.spacing(2)};
|
||||||
width: 100%;
|
width: calc(100% - ${({ theme }) => theme.spacing(4)});
|
||||||
`;
|
`;
|
||||||
|
|
||||||
const StyledTimelineItemContainer = styled.div`
|
const StyledTimelineItemContainer = styled.div`
|
||||||
align-items: center;
|
align-items: center;
|
||||||
align-self: stretch;
|
align-self: stretch;
|
||||||
display: flex;
|
display: flex;
|
||||||
gap: 16px;
|
gap: ${({ theme }) => theme.spacing(4)};
|
||||||
`;
|
`;
|
||||||
|
|
||||||
type OwnProps = {
|
type OwnProps = {
|
||||||
|
|||||||
102
front/src/modules/companies/components/AddPersonToCompany.tsx
Normal file
102
front/src/modules/companies/components/AddPersonToCompany.tsx
Normal file
@ -0,0 +1,102 @@
|
|||||||
|
import { useState } from 'react';
|
||||||
|
import { getOperationName } from '@apollo/client/utilities';
|
||||||
|
import styled from '@emotion/styled';
|
||||||
|
import { flip, offset, useFloating } from '@floating-ui/react';
|
||||||
|
import { IconPlus } from '@tabler/icons-react';
|
||||||
|
|
||||||
|
import {
|
||||||
|
PeoplePicker,
|
||||||
|
PersonForSelect,
|
||||||
|
} from '@/people/components/PeoplePicker';
|
||||||
|
import { GET_PEOPLE } from '@/people/graphql/queries/getPeople';
|
||||||
|
import { ButtonSize } from '@/ui/button/components/Button';
|
||||||
|
import { IconButton } from '@/ui/button/components/IconButton';
|
||||||
|
import { RelationPickerHotkeyScope } from '@/ui/input/relation-picker/types/RelationPickerHotkeyScope';
|
||||||
|
import { usePreviousHotkeyScope } from '@/ui/utilities/hotkey/hooks/usePreviousHotkeyScope';
|
||||||
|
import { RecoilScope } from '@/ui/utilities/recoil-scope/components/RecoilScope';
|
||||||
|
import { useUpdateOnePersonMutation } from '~/generated/graphql';
|
||||||
|
|
||||||
|
const StyledContainer = styled.div`
|
||||||
|
position: relative;
|
||||||
|
`;
|
||||||
|
|
||||||
|
export function AddPersonToCompany({
|
||||||
|
companyId,
|
||||||
|
peopleIds,
|
||||||
|
}: {
|
||||||
|
companyId: string;
|
||||||
|
peopleIds?: string[];
|
||||||
|
}) {
|
||||||
|
const [isDropdownOpen, setIsDropdownOpen] = useState(false);
|
||||||
|
const [updatePerson] = useUpdateOnePersonMutation();
|
||||||
|
const { refs, floatingStyles } = useFloating({
|
||||||
|
placement: 'right-start',
|
||||||
|
middleware: [flip(), offset({ mainAxis: -20, crossAxis: 25 })],
|
||||||
|
});
|
||||||
|
|
||||||
|
const {
|
||||||
|
setHotkeyScopeAndMemorizePreviousScope,
|
||||||
|
goBackToPreviousHotkeyScope,
|
||||||
|
} = usePreviousHotkeyScope();
|
||||||
|
|
||||||
|
function handlePersonSelected(companyId: string) {
|
||||||
|
return async (newPerson: PersonForSelect | null) => {
|
||||||
|
if (newPerson) {
|
||||||
|
await updatePerson({
|
||||||
|
variables: {
|
||||||
|
where: {
|
||||||
|
id: newPerson.id,
|
||||||
|
},
|
||||||
|
data: {
|
||||||
|
company: { connect: { id: companyId } },
|
||||||
|
},
|
||||||
|
},
|
||||||
|
refetchQueries: [getOperationName(GET_PEOPLE) ?? ''],
|
||||||
|
});
|
||||||
|
handleClosePicker();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
function handleClosePicker() {
|
||||||
|
if (isDropdownOpen) {
|
||||||
|
setIsDropdownOpen(false);
|
||||||
|
goBackToPreviousHotkeyScope();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function handleOpenPicker() {
|
||||||
|
if (!isDropdownOpen) {
|
||||||
|
setIsDropdownOpen(true);
|
||||||
|
setHotkeyScopeAndMemorizePreviousScope(
|
||||||
|
RelationPickerHotkeyScope.RelationPicker,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<RecoilScope>
|
||||||
|
<StyledContainer>
|
||||||
|
<div ref={refs.setReference}>
|
||||||
|
<IconButton
|
||||||
|
icon={<IconPlus size={14} />}
|
||||||
|
onClick={handleOpenPicker}
|
||||||
|
size={ButtonSize.Small}
|
||||||
|
variant={'transparent'}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{isDropdownOpen && (
|
||||||
|
<div ref={refs.setFloating} style={floatingStyles}>
|
||||||
|
<PeoplePicker
|
||||||
|
personId={''}
|
||||||
|
onSubmit={handlePersonSelected(companyId)}
|
||||||
|
onCancel={handleClosePicker}
|
||||||
|
excludePersonIds={peopleIds}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</StyledContainer>
|
||||||
|
</RecoilScope>
|
||||||
|
);
|
||||||
|
}
|
||||||
@ -3,12 +3,13 @@ import styled from '@emotion/styled';
|
|||||||
import { PeopleCard } from '@/people/components/PeopleCard';
|
import { PeopleCard } from '@/people/components/PeopleCard';
|
||||||
import { Company, useGetPeopleQuery } from '~/generated/graphql';
|
import { Company, useGetPeopleQuery } from '~/generated/graphql';
|
||||||
|
|
||||||
|
import { AddPersonToCompany } from './AddPersonToCompany';
|
||||||
|
|
||||||
export type CompanyTeamPropsType = {
|
export type CompanyTeamPropsType = {
|
||||||
company: Pick<Company, 'id'>;
|
company: Pick<Company, 'id'>;
|
||||||
};
|
};
|
||||||
|
|
||||||
const StyledContainer = styled.div`
|
const StyledContainer = styled.div`
|
||||||
align-items: flex-start;
|
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
gap: ${({ theme }) => theme.spacing(2)};
|
gap: ${({ theme }) => theme.spacing(2)};
|
||||||
@ -17,13 +18,10 @@ const StyledContainer = styled.div`
|
|||||||
|
|
||||||
const StyledTitleContainer = styled.div`
|
const StyledTitleContainer = styled.div`
|
||||||
align-items: center;
|
align-items: center;
|
||||||
backdrop-filter: blur(5px);
|
|
||||||
color: ${({ theme }) => theme.font.color.primary};
|
color: ${({ theme }) => theme.font.color.primary};
|
||||||
display: flex;
|
display: flex;
|
||||||
justify-content: space-between;
|
justify-content: space-between;
|
||||||
padding-bottom: ${({ theme }) => theme.spacing(0)};
|
padding-bottom: ${({ theme }) => theme.spacing(0)};
|
||||||
padding-left: ${({ theme }) => theme.spacing(3)};
|
|
||||||
padding-right: ${({ theme }) => theme.spacing(3)};
|
|
||||||
padding-top: ${({ theme }) => theme.spacing(3)};
|
padding-top: ${({ theme }) => theme.spacing(3)};
|
||||||
`;
|
`;
|
||||||
|
|
||||||
@ -55,12 +53,15 @@ export function CompanyTeam({ company }: CompanyTeamPropsType) {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const peopleIds = data?.people?.map(({ id }) => id);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
{Boolean(data?.people?.length) && (
|
{Boolean(data?.people?.length) && (
|
||||||
<StyledContainer>
|
<StyledContainer>
|
||||||
<StyledTitleContainer>
|
<StyledTitleContainer>
|
||||||
<StyledTitle>Team</StyledTitle>
|
<StyledTitle>Team</StyledTitle>
|
||||||
|
<AddPersonToCompany companyId={company.id} peopleIds={peopleIds} />
|
||||||
</StyledTitleContainer>
|
</StyledTitleContainer>
|
||||||
<StyledListContainer>
|
<StyledListContainer>
|
||||||
{data?.people?.map((person, id) => (
|
{data?.people?.map((person, id) => (
|
||||||
|
|||||||
@ -61,7 +61,7 @@ const StyledTitle = styled.div`
|
|||||||
|
|
||||||
const StyledJobTitle = styled.div`
|
const StyledJobTitle = styled.div`
|
||||||
border-radius: ${({ theme }) => theme.spacing(1)};
|
border-radius: ${({ theme }) => theme.spacing(1)};
|
||||||
color: ${({ theme }) => theme.font.color.secondary};
|
color: ${({ theme }) => theme.font.color.tertiary};
|
||||||
padding-bottom: ${({ theme }) => theme.spacing(0.5)};
|
padding-bottom: ${({ theme }) => theme.spacing(0.5)};
|
||||||
padding-left: ${({ theme }) => theme.spacing(0)};
|
padding-left: ${({ theme }) => theme.spacing(0)};
|
||||||
padding-right: ${({ theme }) => theme.spacing(2)};
|
padding-right: ${({ theme }) => theme.spacing(2)};
|
||||||
|
|||||||
@ -10,13 +10,19 @@ export type OwnProps = {
|
|||||||
personId: string | null;
|
personId: string | null;
|
||||||
onSubmit: (newPersonId: PersonForSelect | null) => void;
|
onSubmit: (newPersonId: PersonForSelect | null) => void;
|
||||||
onCancel?: () => void;
|
onCancel?: () => void;
|
||||||
|
excludePersonIds?: string[];
|
||||||
};
|
};
|
||||||
|
|
||||||
type PersonForSelect = EntityForSelect & {
|
export type PersonForSelect = EntityForSelect & {
|
||||||
entityType: Entity.Person;
|
entityType: Entity.Person;
|
||||||
};
|
};
|
||||||
|
|
||||||
export function PeoplePicker({ personId, onSubmit, onCancel }: OwnProps) {
|
export function PeoplePicker({
|
||||||
|
personId,
|
||||||
|
onSubmit,
|
||||||
|
onCancel,
|
||||||
|
excludePersonIds,
|
||||||
|
}: OwnProps) {
|
||||||
const [searchFilter] = useRecoilScopedState(
|
const [searchFilter] = useRecoilScopedState(
|
||||||
relationPickerSearchFilterScopedState,
|
relationPickerSearchFilterScopedState,
|
||||||
);
|
);
|
||||||
@ -34,6 +40,7 @@ export function PeoplePicker({ personId, onSubmit, onCancel }: OwnProps) {
|
|||||||
}),
|
}),
|
||||||
orderByField: 'firstName',
|
orderByField: 'firstName',
|
||||||
searchOnFields: ['firstName', 'lastName'],
|
searchOnFields: ['firstName', 'lastName'],
|
||||||
|
excludePersonIds,
|
||||||
});
|
});
|
||||||
|
|
||||||
async function handleEntitySelected(
|
async function handleEntitySelected(
|
||||||
|
|||||||
@ -60,6 +60,7 @@ export function useFilteredSearchEntityQuery<
|
|||||||
mappingFunction,
|
mappingFunction,
|
||||||
limit,
|
limit,
|
||||||
searchFilter, // TODO: put in a scoped recoil state
|
searchFilter, // TODO: put in a scoped recoil state
|
||||||
|
excludePersonIds = [],
|
||||||
}: {
|
}: {
|
||||||
queryHook: (
|
queryHook: (
|
||||||
queryOptions?: Apollo.QueryHookOptions<
|
queryOptions?: Apollo.QueryHookOptions<
|
||||||
@ -74,6 +75,7 @@ export function useFilteredSearchEntityQuery<
|
|||||||
mappingFunction: (entity: EntityType) => CustomEntityForSelect;
|
mappingFunction: (entity: EntityType) => CustomEntityForSelect;
|
||||||
limit?: number;
|
limit?: number;
|
||||||
searchFilter: string;
|
searchFilter: string;
|
||||||
|
excludePersonIds?: string[];
|
||||||
}): EntitiesForMultipleEntitySelect<CustomEntityForSelect> {
|
}): EntitiesForMultipleEntitySelect<CustomEntityForSelect> {
|
||||||
const { loading: selectedEntitiesLoading, data: selectedEntitiesData } =
|
const { loading: selectedEntitiesLoading, data: selectedEntitiesData } =
|
||||||
queryHook({
|
queryHook({
|
||||||
@ -129,7 +131,7 @@ export function useFilteredSearchEntityQuery<
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
id: {
|
id: {
|
||||||
notIn: selectedIds,
|
notIn: [...selectedIds, ...excludePersonIds],
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
|||||||
@ -6,6 +6,7 @@ export const ShowPageContainer = styled.div`
|
|||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: ${() => (useIsMobile() ? 'column' : 'row')};
|
flex-direction: ${() => (useIsMobile() ? 'column' : 'row')};
|
||||||
gap: ${({ theme }) => (useIsMobile() ? theme.spacing(3) : '0')};
|
gap: ${({ theme }) => (useIsMobile() ? theme.spacing(3) : '0')};
|
||||||
height: 100%;
|
height: ${() => (useIsMobile() ? '100%' : 'auto')};
|
||||||
|
overflow-x: ${() => (useIsMobile() ? 'hidden' : 'auto')};
|
||||||
width: ${() => (useIsMobile() ? `calc(100% - 2px);` : '100%')};
|
width: ${() => (useIsMobile() ? `calc(100% - 2px);` : '100%')};
|
||||||
`;
|
`;
|
||||||
|
|||||||
@ -14,11 +14,12 @@ export const ShowPageLeftContainer = styled.div`
|
|||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
gap: ${({ theme }) => theme.spacing(3)};
|
gap: ${({ theme }) => theme.spacing(3)};
|
||||||
overflow-y: scroll;
|
|
||||||
padding: 0px ${({ theme }) => theme.spacing(3)};
|
padding: 0px ${({ theme }) => theme.spacing(3)};
|
||||||
width: ${({ theme }) => {
|
width: ${({ theme }) => {
|
||||||
const isMobile = useIsMobile();
|
const isMobile = useIsMobile();
|
||||||
|
|
||||||
return isMobile ? `calc(100% - ${theme.spacing(6)})` : '320px';
|
return isMobile ? `calc(100% - ${theme.spacing(6)})` : '320px';
|
||||||
}};
|
}};
|
||||||
|
|
||||||
|
z-index: 10;
|
||||||
`;
|
`;
|
||||||
|
|||||||
@ -1,9 +1,16 @@
|
|||||||
import styled from '@emotion/styled';
|
import styled from '@emotion/styled';
|
||||||
|
|
||||||
|
import { useIsMobile } from '@/ui/utilities/responsive/hooks/useIsMobile';
|
||||||
|
|
||||||
export const ShowPageRightContainer = styled.div`
|
export const ShowPageRightContainer = styled.div`
|
||||||
display: flex;
|
display: flex;
|
||||||
flex: 1 0 0;
|
flex: 1 0 0;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
overflow: hidden;
|
overflow: ${() => (useIsMobile() ? 'none' : 'hidden')};
|
||||||
|
width: ${({ theme }) => {
|
||||||
|
const isMobile = useIsMobile();
|
||||||
|
|
||||||
|
return isMobile ? `calc(100% - ${theme.spacing(6)})` : 'auto';
|
||||||
|
}};
|
||||||
`;
|
`;
|
||||||
|
|||||||
@ -30,7 +30,6 @@ export function usePreviousHotkeyScope() {
|
|||||||
.valueOrThrow();
|
.valueOrThrow();
|
||||||
|
|
||||||
setHotkeyScope(scope, customScopes);
|
setHotkeyScope(scope, customScopes);
|
||||||
|
|
||||||
setPreviousHotkeyScope(currentHotkeyScope);
|
setPreviousHotkeyScope(currentHotkeyScope);
|
||||||
},
|
},
|
||||||
[setPreviousHotkeyScope],
|
[setPreviousHotkeyScope],
|
||||||
|
|||||||
@ -26,7 +26,6 @@ export function useSetHotkeyScope() {
|
|||||||
const currentHotkeyScope = await snapshot.getPromise(
|
const currentHotkeyScope = await snapshot.getPromise(
|
||||||
currentHotkeyScopeState,
|
currentHotkeyScopeState,
|
||||||
);
|
);
|
||||||
|
|
||||||
if (currentHotkeyScope.scope === hotkeyScopeToSet) {
|
if (currentHotkeyScope.scope === hotkeyScopeToSet) {
|
||||||
if (!isDefined(customScopes)) {
|
if (!isDefined(customScopes)) {
|
||||||
if (
|
if (
|
||||||
@ -68,8 +67,8 @@ export function useSetHotkeyScope() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
scopesToSet.push(newHotkeyScope.scope);
|
scopesToSet.push(newHotkeyScope.scope);
|
||||||
|
|
||||||
set(internalHotkeysEnabledScopesState, scopesToSet);
|
set(internalHotkeysEnabledScopesState, scopesToSet);
|
||||||
|
set(currentHotkeyScopeState, newHotkeyScope);
|
||||||
},
|
},
|
||||||
[],
|
[],
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user