Files
twenty/front/src/modules/pipeline/components/PipelineAddButton.tsx
T
Charles Bochet 258685467b Refactor UI folder (#2016)
* Added Overview page

* Revised Getting Started page

* Minor revision

* Edited readme, minor modifications to docs

* Removed sweep.yaml, .devcontainer, .ergomake

* Moved security.md to .github, added contributing.md

* changes as per code review

* updated contributing.md

* fixed broken links & added missing links in doc, improved structure

* fixed link in wsl setup

* fixed server link, added https cloning in yarn-setup

* removed package-lock.json

* added doc card, admonitions

* removed underline from nav buttons

* refactoring modules/ui

* refactoring modules/ui

* Change folder case

* Fix theme location

* Fix case 2

* Fix storybook

---------

Co-authored-by: Nimra Ahmed <nimra1408@gmail.com>
Co-authored-by: Nimra Ahmed <50912134+nimraahmed@users.noreply.github.com>
2023-10-14 00:04:29 +02:00

83 lines
2.6 KiB
TypeScript

import { CompanyProgressPicker } from '@/companies/components/CompanyProgressPicker';
import { useCreateCompanyProgress } from '@/companies/hooks/useCreateCompanyProgress';
import { PageHotkeyScope } from '@/types/PageHotkeyScope';
import { ViewBarDropdownButton } from '@/ui/data/view-bar/components/ViewBarDropdownButton';
import { IconPlus } from '@/ui/display/icon/index';
import { useSnackBar } from '@/ui/feedback/snack-bar/hooks/useSnackBar';
import { IconButton } from '@/ui/input/button/components/IconButton';
import { EntityForSelect } from '@/ui/input/relation-picker/types/EntityForSelect';
import { RelationPickerHotkeyScope } from '@/ui/input/relation-picker/types/RelationPickerHotkeyScope';
import { useDropdown } from '@/ui/layout/dropdown/hooks/useDropdown';
import { logError } from '~/utils/logError';
export const PipelineAddButton = () => {
const { enqueueSnackBar } = useSnackBar();
const { closeDropdown, toggleDropdown } = useDropdown({
dropdownScopeId: 'add-pipeline-progress',
});
const createCompanyProgress = useCreateCompanyProgress();
const handleCompanySelected = (
selectedCompany: EntityForSelect | null,
selectedPipelineStageId: string | null,
) => {
if (!selectedCompany?.id) {
enqueueSnackBar(
'There was a problem with the company selection, please retry.',
{
variant: 'error',
},
);
logError('There was a problem with the company selection, please retry.');
return;
}
if (!selectedPipelineStageId) {
enqueueSnackBar(
'There was a problem with the pipeline stage selection, please retry.',
{
variant: 'error',
},
);
logError('There was a problem with the pipeline stage selection.');
return;
}
closeDropdown();
createCompanyProgress(selectedCompany.id, selectedPipelineStageId);
};
return (
<ViewBarDropdownButton
dropdownId="add-pipeline-progress"
buttonComponent={
<IconButton
Icon={IconPlus}
size="medium"
dataTestId="add-company-progress-button"
accent="default"
variant="secondary"
onClick={toggleDropdown}
/>
}
dropdownComponents={
<CompanyProgressPicker
companyId={null}
onSubmit={handleCompanySelected}
onCancel={closeDropdown}
/>
}
hotkey={{
key: 'c',
scope: PageHotkeyScope.OpportunitiesPage,
}}
dropdownHotkeyScope={{
scope: RelationPickerHotkeyScope.RelationPicker,
}}
/>
);
};