@@ -44,6 +44,17 @@ import { getModalById, PLATE_CHANGE_PASSWORD, RESEND_INVATION_PASSWORD } from '# import { formatDateStatus, formatEmail, translateEmailStatus } from '../../lib/lib' import { XMark } from '#/features/remove-person' import { useShowDataStore } from '#/shared/lib/hooks/use-show-data' +import { resendInvation } from '#/features/resend-invation-corp/api/resend-invation' + +interface ModalWithState { + setState: (isOpen: boolean, props?: any) => void +} + +interface ModalWithOpen { + open: (props?: any) => void +} + +type ModalType = ModalWithState | ModalWithOpen | ((props?: any) => void) | null export const SecurityList = ({ securityList, @@ -59,8 +70,8 @@ export const SecurityList = ({ const [inviteModal, setInviteModal] = useState(false) const [currentPerson, setCurrentPerson] = useState(null) - const passChangeModal = getModalById(PLATE_CHANGE_PASSWORD) - const passResendModal = getModalById(RESEND_INVATION_PASSWORD) + const passChangeModal = getModalById(PLATE_CHANGE_PASSWORD) as ModalType + const passResendModal = getModalById(RESEND_INVATION_PASSWORD) as ModalType useEffect(() => { setPersons(securityList) @@ -92,7 +103,6 @@ export const SecurityList = ({ el.token_limit = limit return el } - return el }) ) @@ -100,6 +110,56 @@ export const SecurityList = ({ showMessage(`Данные сотрудника ${email} изменены!`, 'success') } + const handleOpenResendModal = async (email: string) => { + try { + const response = await resendInvation(email, data?.access) + + if (response.status == 200) { + showMessage('Приглашение переотправлено!', 'success') + setPersons((prev) => + prev?.map((el) => { + if (el.email === email) { + return { ...el, acceptance_status: 'pending' as const } + } + return el + }) ?? null + ) + } else { + const errorMessage = typeof response.data === 'string' + ? response.data + : response.data?.detail || 'Ошибка при отправке приглашения' + showMessage(errorMessage, 'error') + } + } catch (error) { + showMessage('Произошла ошибка при отправке приглашения', 'error') + } + } + + const handleChangePassword = (email: string) => { + if (passChangeModal && 'setState' in passChangeModal) { + passChangeModal.setState(true, { email }) + } else if (passChangeModal && 'open' in passChangeModal) { + passChangeModal.open({ email }) + } else if (typeof passChangeModal === 'function') { + passChangeModal({ email, isOpen: true }) + } else { + console.error('Модальное окно смены пароля не настроено корректно', passChangeModal) + showMessage('Ошибка открытия модального окна', 'error') + } + } + + const handleResendInvitation = (email: string) => { + if (passResendModal && 'setState' in passResendModal) { + passResendModal.setState(true, { email }) + } else if (passResendModal && 'open' in passResendModal) { + passResendModal.open({ email }) + } else if (typeof passResendModal === 'function') { + passResendModal({ email, isOpen: true }) + } else { + handleOpenResendModal(email) + } + } + useEffect(() => { setSearchPersons((pre) => { if (!persons) { @@ -180,11 +240,7 @@ export const SecurityList = ({ {statusPerson === 'Приглашен' ? ( @@ -349,4 +401,4 @@ export const InviteSecurityModal: FC = ({ open, onClose, showN ) -} +} \ No newline at end of file