import { AppDispatch } from "app/store"; import React, { useCallback, useEffect, useState } from "react"; import styles from "styles/app.module.scss"; import { useDispatch, useSelector } from "react-redux"; import { useTranslation } from "react-i18next"; import { USER_ROLES } from "components/auth/constants"; import { changeUpdateAuthorId, changeUpdateAutoRenew, changeUpdateEncryption, changeUpdateEncryptionPassword, changeUpdateNotification, changeUpdatePrompt, changeUpdateRole, changeHasPasswordMask, cleanupUpdateUser, selectHasPasswordMask, selectIsLoading, selectUpdateUser, selectUpdateValidationErrors, updateUserAsync, listUsersAsync, } from "features/user"; import { getTranslationID } from "translation"; import close from "../../assets/images/close.svg"; import progress_activit from "../../assets/images/progress_activit.svg"; interface UserUpdatePopupProps { isOpen: boolean; onClose: () => void; clearUserSearchInputs: () => void; } export const UserUpdatePopup: React.FC = (props) => { const { isOpen, onClose, clearUserSearchInputs } = props; const dispatch: AppDispatch = useDispatch(); const { t } = useTranslation(); const closePopup = useCallback(() => { setIsPushCreateButton(false); dispatch(cleanupUpdateUser()); onClose(); }, [onClose, dispatch]); const { hasErrorEmptyAuthorId, hasErrorIncorrectAuthorId, hasErrorIncorrectEncryptionPassword, } = useSelector(selectUpdateValidationErrors); const [isPasswordHide, setIsPasswordHide] = useState(true); const [isPushCreateButton, setIsPushCreateButton] = useState(false); const user = useSelector(selectUpdateUser); const isLoading = useSelector(selectIsLoading); const hasPasswordMask = useSelector(selectHasPasswordMask); const [canChangeRole, setCanChangeRole] = useState(true); // 開閉時のみ実行 useEffect(() => { setCanChangeRole(user.role === USER_ROLES.NONE); setIsPasswordHide(true); // eslint-disable-next-line react-hooks/exhaustive-deps }, [isOpen]); const onUpdateUser = useCallback(async () => { setIsPushCreateButton(true); if ( hasErrorEmptyAuthorId || hasErrorIncorrectAuthorId || hasErrorIncorrectEncryptionPassword ) { return; } const { meta } = await dispatch(updateUserAsync()); setIsPushCreateButton(false); if (meta.requestStatus === "fulfilled") { closePopup(); clearUserSearchInputs(); dispatch(listUsersAsync()); } }, [ dispatch, closePopup, hasErrorEmptyAuthorId, hasErrorIncorrectAuthorId, hasErrorIncorrectEncryptionPassword, ]); return (

{t(getTranslationID("userListPage.label.editUser"))}

{t(getTranslationID("userListPage.label.personal"))}
{t(getTranslationID("userListPage.label.name"))}
{t(getTranslationID("userListPage.label.email"))}
{t(getTranslationID("userListPage.label.role"))}
{/** Author 選択時に表示 */} {user.role === USER_ROLES.AUTHOR && (
{t(getTranslationID("userListPage.label.authorID"))}
{ dispatch( changeUpdateAuthorId({ authorId: e.target.value.toUpperCase(), }) ); }} /> {isPushCreateButton && hasErrorEmptyAuthorId && ( {t( getTranslationID("signupPage.message.inputEmptyError") )} )} {isPushCreateButton && hasErrorIncorrectAuthorId && ( {t( getTranslationID( "userListPage.message.authorIdIncorrectError" ) )} )}
{t(getTranslationID("userListPage.label.encryption"))}
{/** Encryptionチェックでパスワード欄表示 */}

{t( getTranslationID("userListPage.label.encryptionPassword") )} { if (hasPasswordMask) { dispatch( changeHasPasswordMask({ hasPasswordMask: false }) ); dispatch( changeUpdateEncryptionPassword({ encryptionPassword: "", }) ); } }} onChange={(e) => { if (!hasPasswordMask) { dispatch( changeUpdateEncryptionPassword({ encryptionPassword: e.target.value, }) ); } }} /> { setIsPasswordHide(!isPasswordHide); }} onKeyDown={() => { setIsPasswordHide(!isPasswordHide); }} role="button" tabIndex={0} aria-label="IconEye" /> {isPushCreateButton && hasErrorIncorrectEncryptionPassword && ( {t( getTranslationID( "userListPage.message.encryptionPasswordCorrectError" ) )} )} {t( getTranslationID( "userListPage.label.encryptionPasswordTerm" ) )}

{t(getTranslationID("userListPage.label.prompt"))}
)}
{t(getTranslationID("userListPage.label.setting"))}

Loading
); };