import { useState, useCallback } from 'react'; import { useTranslation } from 'react-i18next'; import { Modal, ModalHeader, ModalBody, ModalFooter, } from 'reactstrap'; import { useGrantedGroupsInheritanceSelectModalActions, useGrantedGroupsInheritanceSelectModalStatus, } from '~/states/ui/modal/granted-groups-inheritance-select'; /** * GrantedGroupsInheritanceSelectModalSubstance - Presentation component (heavy logic, rendered only when isOpen) */ type GrantedGroupsInheritanceSelectModalSubstanceProps = { onCreateBtnClick: ((onlyInheritUserRelatedGrantedGroups: boolean) => Promise) | undefined; closeModal: () => void; }; const GrantedGroupsInheritanceSelectModalSubstance = (props: GrantedGroupsInheritanceSelectModalSubstanceProps): React.JSX.Element => { const { onCreateBtnClick: _onCreateBtnClick, closeModal } = props; const { t } = useTranslation(); const [onlyInheritUserRelatedGrantedGroups, setOnlyInheritUserRelatedGrantedGroups] = useState(false); const onCreateBtnClick = useCallback(async() => { await _onCreateBtnClick?.(onlyInheritUserRelatedGrantedGroups); setOnlyInheritUserRelatedGrantedGroups(false); // reset to false after create request }, [_onCreateBtnClick, onlyInheritUserRelatedGrantedGroups]); const setInheritAll = useCallback(() => setOnlyInheritUserRelatedGrantedGroups(false), []); const setInheritRelatedOnly = useCallback(() => setOnlyInheritUserRelatedGrantedGroups(true), []); return ( <> closeModal()}> {t('modal_granted_groups_inheritance_select.select_granted_groups')}
); }; /** * GrantedGroupsInheritanceSelectModal - Container component (lightweight, always rendered) */ export const GrantedGroupsInheritanceSelectModal = (): React.JSX.Element => { const { isOpened, onCreateBtnClick } = useGrantedGroupsInheritanceSelectModalStatus(); const { close: closeModal } = useGrantedGroupsInheritanceSelectModalActions(); return ( closeModal()} > {isOpened && ( )} ); };