diff --git a/frontend/src/components/common/Listbox/Listbox.hooks.ts b/frontend/src/components/common/Listbox/Listbox.hooks.ts new file mode 100644 index 00000000..daf95fab --- /dev/null +++ b/frontend/src/components/common/Listbox/Listbox.hooks.ts @@ -0,0 +1,10 @@ +import { MouseEvent } from 'react'; +import { ListboxProps } from './Listbox.interface'; + +export const useListBox = (onClear: ListboxProps['onClear']) => { + const handleClear = (e: MouseEvent) => { + e.stopPropagation(); + onClear?.(); + }; + return { handleClear }; +}; diff --git a/frontend/src/components/common/Listbox/Listbox.interface.ts b/frontend/src/components/common/Listbox/Listbox.interface.ts index 5e2a1645..77e2eab7 100644 --- a/frontend/src/components/common/Listbox/Listbox.interface.ts +++ b/frontend/src/components/common/Listbox/Listbox.interface.ts @@ -4,5 +4,5 @@ export interface ListboxProps { name: string; options: Option[]; placeholder?: string; - handleClear?: () => void; + onClear?: () => void; } diff --git a/frontend/src/components/common/Listbox/Listbox.tsx b/frontend/src/components/common/Listbox/Listbox.tsx index e2055cb6..633545c4 100644 --- a/frontend/src/components/common/Listbox/Listbox.tsx +++ b/frontend/src/components/common/Listbox/Listbox.tsx @@ -6,9 +6,11 @@ import { ListboxProps } from './Listbox.interface'; import { generateClassNames } from '@app/utils'; import { ChevronUpIcon } from '@app/static/icons/ChevronUpIcon'; import { CloseIcon } from '@app/static/icons/CloseIcon'; +import { useListBox } from './Listbox.hooks'; -export const Listbox: FC = ({ name, options, placeholder, handleClear }) => { +export const Listbox: FC = ({ name, options, placeholder, onClear }) => { const { control } = useFormContext(); + const { handleClear } = useListBox(onClear); return ( = ({ name, options, placeholder, handleCl
{!value && placeholder ? placeholder : value?.name} {selected ? ( -
{ - e.stopPropagation(); - handleClear?.(); - }} - > +
) : ( diff --git a/frontend/src/components/common/Tabs/Tabs.hooks.ts b/frontend/src/components/common/Tabs/Tabs.hooks.ts new file mode 100644 index 00000000..41102f6e --- /dev/null +++ b/frontend/src/components/common/Tabs/Tabs.hooks.ts @@ -0,0 +1,10 @@ +import { ChangeEvent } from 'react'; +import { TabsProps } from './Tabs.interface'; + +export const useTabs = (tabs: TabsProps['tabs'], onTabChange: TabsProps['onTabChange']) => { + const handleSelectTab = (e: ChangeEvent) => { + const tab = tabs.find((tab) => tab.name === e.target.value); + if (tab) onTabChange(tab); + }; + return { handleSelectTab }; +}; diff --git a/frontend/src/components/common/Tabs/Tabs.tsx b/frontend/src/components/common/Tabs/Tabs.tsx index 75ef5236..106befc6 100644 --- a/frontend/src/components/common/Tabs/Tabs.tsx +++ b/frontend/src/components/common/Tabs/Tabs.tsx @@ -1,8 +1,10 @@ import { FC } from 'react'; import { TabsProps } from './Tabs.interface'; import { generateClassNames } from '@app/utils'; +import { useTabs } from './Tabs.hooks'; export const Tabs: FC = ({ tabs, current, onTabChange, className }) => { + const { handleSelectTab } = useTabs(tabs, onTabChange); return (
@@ -12,10 +14,7 @@ export const Tabs: FC = ({ tabs, current, onTabChange, className }) =