-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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; | ||
|
@@ -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, | ||
}); | ||
|
||
setViewableRecordId(newRecordId); | ||
setViewableRecordNameSingular(CoreObjectNameSingular.Company); | ||
openRightDrawer(RightDrawerPages.ViewRecord); | ||
|
||
Comment on lines
+63
to
+65
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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> | ||
)} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -60,6 +60,7 @@ export const useFilteredSearchEntityQuery = ({ | |
filter: notFilter, | ||
limit: limit ?? DEFAULT_SEARCH_REQUEST_LIMIT, | ||
searchInput: searchFilter, | ||
fetchPolicy: 'cache-and-network', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am not sure about this one! |
||
}); | ||
|
||
return { | ||
|
There was a problem hiding this comment.
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.