Enables creating an opportunityCard instantly if company field is disabled (#6316) (#6911)

fixes #6316

---------

Co-authored-by: martmull <martmull@hotmail.fr>
This commit is contained in:
Faisal-imtiyaz123 2024-09-06 15:23:53 +05:30 committed by GitHub
parent 6c15033511
commit d36486b65e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 38 additions and 12 deletions

View File

@ -1,10 +1,12 @@
import { RecordBoardContext } from '@/object-record/record-board/contexts/RecordBoardContext';
import { RecordBoardColumnContext } from '@/object-record/record-board/record-board-column/contexts/RecordBoardColumnContext';
import { useIsOpportunitiesCompanyFieldDisabled } from '@/object-record/record-board/record-board-column/hooks/useIsOpportunitiesCompanyFieldDisabled';
import { useEntitySelectSearch } from '@/object-record/relation-picker/hooks/useEntitySelectSearch';
import { EntityForSelect } from '@/object-record/relation-picker/types/EntityForSelect';
import { RelationPickerHotkeyScope } from '@/object-record/relation-picker/types/RelationPickerHotkeyScope';
import { usePreviousHotkeyScope } from '@/ui/utilities/hotkey/hooks/usePreviousHotkeyScope';
import { useCallback, useContext, useState } from 'react';
import { isDefined } from 'twenty-ui';
export const useAddNewOpportunity = (position: string) => {
const [isCreatingCard, setIsCreatingCard] = useState(false);
@ -20,21 +22,19 @@ export const useAddNewOpportunity = (position: string) => {
const { resetSearchFilter } = useEntitySelectSearch({
relationPickerScopeId: 'relation-picker',
});
const { isOpportunitiesCompanyFieldDisabled } =
useIsOpportunitiesCompanyFieldDisabled();
const handleEntitySelect = useCallback(
(company?: EntityForSelect) => {
setIsCreatingCard(false);
goBackToPreviousHotkeyScope();
resetSearchFilter();
if (company !== undefined) {
createOneRecord({
name: company.name,
companyId: company.id,
position: position,
[selectFieldMetadataItem.name]: columnDefinition.value,
});
}
createOneRecord({
name: company?.name,
companyId: company?.id,
position: position,
[selectFieldMetadataItem.name]: columnDefinition.value,
});
},
[
columnDefinition,
@ -47,11 +47,19 @@ export const useAddNewOpportunity = (position: string) => {
);
const handleAddNewOpportunityClick = useCallback(() => {
setIsCreatingCard(true);
if (isOpportunitiesCompanyFieldDisabled) {
handleEntitySelect();
} else {
setIsCreatingCard(true);
}
setHotkeyScopeAndMemorizePreviousScope(
RelationPickerHotkeyScope.RelationPicker,
);
}, [setHotkeyScopeAndMemorizePreviousScope]);
}, [
setHotkeyScopeAndMemorizePreviousScope,
isOpportunitiesCompanyFieldDisabled,
handleEntitySelect,
]);
const handleCancel = useCallback(() => {
resetSearchFilter();

View File

@ -0,0 +1,17 @@
import { useObjectMetadataItem } from '@/object-metadata/hooks/useObjectMetadataItem';
import { CoreObjectNameSingular } from '@/object-metadata/types/CoreObjectNameSingular';
export const useIsOpportunitiesCompanyFieldDisabled = () => {
const { objectMetadataItem: opportunityMetadataItem } = useObjectMetadataItem(
{
objectNameSingular: CoreObjectNameSingular.Opportunity,
},
);
const isOpportunitiesCompanyFieldDisabled =
!opportunityMetadataItem.fields.find(
(field) => field.name === CoreObjectNameSingular.Company,
)?.isActive || false;
return {
isOpportunitiesCompanyFieldDisabled,
};
};

View File

@ -25,6 +25,7 @@ export default defineConfig(({ command, mode }) => {
? path.resolve(__dirname, './tsconfig.build.json')
: path.resolve(__dirname, './tsconfig.dev.json');
const checkers: Checkers = {
overlay: false,
};