mirror of
https://github.com/twentyhq/twenty.git
synced 2024-12-26 13:31:45 +03:00
fixes #6316 --------- Co-authored-by: martmull <martmull@hotmail.fr>
This commit is contained in:
parent
6c15033511
commit
d36486b65e
@ -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();
|
||||
|
@ -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,
|
||||
};
|
||||
};
|
@ -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,
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user