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

fix - add new button on opportunity board company picker doesnt work #8488

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
import styled from '@emotion/styled';

import { CoreObjectNameSingular } from '@/object-metadata/types/CoreObjectNameSingular';
import { useCreateOneRecord } from '@/object-record/hooks/useCreateOneRecord';
import { useAddNewCard } from '@/object-record/record-board/record-board-column/hooks/useAddNewCard';
import { recordBoardNewRecordByColumnIdSelector } from '@/object-record/record-board/states/selectors/recordBoardNewRecordByColumnIdSelector';
import { viewableRecordIdState } from '@/object-record/record-right-drawer/states/viewableRecordIdState';
import { viewableRecordNameSingularState } from '@/object-record/record-right-drawer/states/viewableRecordNameSingularState';
import { SingleEntitySelect } from '@/object-record/relation-picker/components/SingleEntitySelect';
import { useRecoilValue } from 'recoil';
import { useRightDrawer } from '@/ui/layout/right-drawer/hooks/useRightDrawer';
import { RightDrawerPages } from '@/ui/layout/right-drawer/types/RightDrawerPages';
import styled from '@emotion/styled';
import { useRecoilValue, useSetRecoilState } from 'recoil';
import { v4 } from 'uuid';
import { isDefined } from '~/utils/isDefined';

const StyledCompanyPickerContainer = styled.div`
align-items: center;
Expand All @@ -31,21 +37,56 @@ export const RecordBoardColumnNewOpportunity = ({
scopeId: columnId,
}),
);

const { handleCreateSuccess, handleEntitySelect } = useAddNewCard();

const { createOneRecord: createCompany } = useCreateOneRecord({
objectNameSingular: CoreObjectNameSingular.Company,
});
const { openRightDrawer } = useRightDrawer();

const setViewableRecordId = useSetRecoilState(viewableRecordIdState);
const setViewableRecordNameSingular = useSetRecoilState(
viewableRecordNameSingularState,
);

const createCompanyOpportunityAndOpenRightDrawer = async (
searchInput?: string,
) => {
const newRecordId = v4();

const createdCompany = await createCompany({
id: newRecordId,
name: searchInput,
});

Comment on lines +58 to +61
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

logic: No error handling if company creation fails. Could leave UI in inconsistent state.

setViewableRecordId(newRecordId);
setViewableRecordNameSingular(CoreObjectNameSingular.Company);
openRightDrawer(RightDrawerPages.ViewRecord);

Comment on lines +63 to +65
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: State updates and drawer opening should happen after confirming company creation succeeded

if (isDefined(createdCompany)) {
handleEntitySelect(position, createdCompany);
}
};

return (
<>
{newRecord.isCreating && newRecord.position === position && (
<StyledCompanyPickerContainer>
<SingleEntitySelect
disableBackgroundBlur
onCancel={() => handleCreateSuccess(position, columnId, false)}
onEntitySelected={(company) =>
company ? handleEntitySelect(position, company) : null
}
onCancel={() => {
handleCreateSuccess(position, columnId, false);
}}
onEntitySelected={(company) => {
if (isDefined(company)) {
handleEntitySelect(position, company);
}
}}
relationObjectNameSingular={CoreObjectNameSingular.Company}
relationPickerScopeId="relation-picker"
selectedRelationRecordIds={[]}
onCreate={createCompanyOpportunityAndOpenRightDrawer}
/>
</StyledCompanyPickerContainer>
)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ export const useFilteredSearchEntityQuery = ({
filter: notFilter,
limit: limit ?? DEFAULT_SEARCH_REQUEST_LIMIT,
searchInput: searchFilter,
fetchPolicy: 'cache-and-network',
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure about this one!
But the newly created entities won't get fetched without this.

});

return {
Expand Down
Loading