import React, { useCallback, useEffect, useState } from "react"; import Footer from "components/footer"; import Header from "components/header"; import styles from "styles/app.module.scss"; import { getTranslationID } from "translation"; import { useTranslation } from "react-i18next"; import { AppDispatch } from "app/store"; import { useDispatch, useSelector } from "react-redux"; import { getCompanyNameAsync, getLicenseSummaryAsync, selectLicenseSummaryInfo, selectCompanyName, selectIsLoading, updateRestrictionStatusAsync, } from "features/license/licenseSummary"; import { selectDelegationAccessToken } from "features/auth/selectors"; import { DelegationBar } from "components/delegate"; import { TIERS } from "components/auth/constants"; import { isAdminUser, isApproveTier } from "features/auth/utils"; import { PartnerLicenseInfo, SearchPartner } from "../../api"; import postAdd from "../../assets/images/post_add.svg"; import history from "../../assets/images/history.svg"; import key from "../../assets/images/key.svg"; import block from "../../assets/images/block.svg"; import circle from "../../assets/images/circle.svg"; import returnLabel from "../../assets/images/undo.svg"; import { LicenseOrderPopup } from "./licenseOrderPopup"; import { CardLicenseActivatePopup } from "./cardLicenseActivatePopup"; import { TrialLicenseIssuePopup } from "./trialLicenseIssuePopup"; // eslint-disable-next-line import/no-named-as-default import LicenseOrderHistory from "./licenseOrderHistory"; interface LicenseSummaryProps { onReturn?: () => void; selectedRow?: PartnerLicenseInfo | SearchPartner; } export const LicenseSummary: React.FC = ( props ): JSX.Element => { const { onReturn, selectedRow } = props; const dispatch: AppDispatch = useDispatch(); const [t] = useTranslation(); // 代行操作用のトークンを取得する const delegationAccessToken = useSelector(selectDelegationAccessToken); const isLoading = useSelector(selectIsLoading); // popup制御関係 const [islicenseOrderPopupOpen, setIslicenseOrderPopupOpen] = useState(false); const [isCardLicenseActivatePopupOpen, setIsCardLicenseActivatePopupOpen] = useState(false); const [isTrialLicenseIssuePopupOpen, setIsTrialLicenseIssuePopupOpen] = useState(false); const onlicenseOrderOpen = useCallback(() => { setIslicenseOrderPopupOpen(true); }, [setIslicenseOrderPopupOpen]); const onCardLicenseActivateOpen = useCallback(() => { setIsCardLicenseActivatePopupOpen(true); }, [setIsCardLicenseActivatePopupOpen]); const onTrialLicenseIssueOpen = useCallback(() => { setIsTrialLicenseIssuePopupOpen(true); }, [setIsTrialLicenseIssuePopupOpen]); // 呼び出し画面制御関係 const [islicenseOrderHistoryOpen, setIsLicenseOrderHistoryOpen] = useState(false); const onLicenseOrderHistoryOpen = useCallback(() => { setIsLicenseOrderHistoryOpen(true); }, [setIsLicenseOrderHistoryOpen]); // apiからの値取得関係 const licenseSummaryInfo = useSelector(selectLicenseSummaryInfo); const companyName = useSelector(selectCompanyName); const isTier1 = isApproveTier([TIERS.TIER1]); const isTier2 = isApproveTier([TIERS.TIER2]); const isAdmin = isAdminUser(); useEffect(() => { dispatch(getLicenseSummaryAsync({ selectedRow })); dispatch(getCompanyNameAsync({ selectedRow })); // eslint-disable-next-line react-hooks/exhaustive-deps }, [dispatch]); // Return押下時の処理 const returnClick = useCallback(() => { if (onReturn) { onReturn(); } }, [onReturn]); const onStorageAvailableChange = useCallback( async (e: React.ChangeEvent) => { if ( /* eslint-disable-next-line no-alert */ !window.confirm( t( getTranslationID( "LicenseSummaryPage.message.storageUnavalableSwitchingConfirm" ) ) ) ) { return; } const restricted = e.target.checked; const accountId = selectedRow?.accountId; // 本関数が実行されるときはselectedRowが存在する前提のため、accountIdが存在しない場合の処理は不要 if (!accountId) return; const { meta } = await dispatch( updateRestrictionStatusAsync({ accountId, restricted }) ); if (meta.requestStatus === "fulfilled") { dispatch(getLicenseSummaryAsync({ selectedRow })); } }, [dispatch, selectedRow, t] ); return ( <> {/* isPopupOpenがfalseの場合はポップアップのhtmlを生成しないように対応。これによりポップアップは都度生成されて初期化の考慮が減る */} {islicenseOrderPopupOpen && ( { setIslicenseOrderPopupOpen(false); dispatch(getLicenseSummaryAsync({ selectedRow })); }} /> )} {isCardLicenseActivatePopupOpen && ( { setIsCardLicenseActivatePopupOpen(false); }} /> )} {isTrialLicenseIssuePopupOpen && ( { setIsTrialLicenseIssuePopupOpen(false); dispatch(getLicenseSummaryAsync({ selectedRow })); }} selectedRow={selectedRow} /> )} {islicenseOrderHistoryOpen && ( { setIsLicenseOrderHistoryOpen(false); }} selectedRow={selectedRow} /> )} {!islicenseOrderHistoryOpen && (
{delegationAccessToken && }

{t(getTranslationID("LicenseSummaryPage.label.title"))}

{companyName}

{t( getTranslationID( "LicenseSummaryPage.label.licenseLabel" ) )}

{t( getTranslationID( "LicenseSummaryPage.label.totalLicense" ) )}
{licenseSummaryInfo.totalLicense}
{t( getTranslationID( "LicenseSummaryPage.label.freeLicense" ) )}
{licenseSummaryInfo.freeLicense}
{t( getTranslationID( "LicenseSummaryPage.label.reusableLicense" ) )}
{licenseSummaryInfo.reusableLicense}
{t( getTranslationID( "LicenseSummaryPage.label.allocatedLicense" ) )}
{licenseSummaryInfo.allocatedLicense}
{t( getTranslationID( "LicenseSummaryPage.label.expiringWithin14daysLicense" ) )}
{licenseSummaryInfo.expiringWithin14daysLicense}
{t( getTranslationID("LicenseSummaryPage.label.shortage") )}
0 ? styles.isAlert : "" } > {licenseSummaryInfo.shortage}
{t( getTranslationID( "LicenseSummaryPage.label.issueRequesting" ) )}
{licenseSummaryInfo.issueRequesting}
{isTier1 && isAdmin && (

{/* eslint-disable-next-line jsx-a11y/label-has-associated-control */}

)}

{t( getTranslationID( "LicenseSummaryPage.label.storageLabel" ) )}

{t( getTranslationID( "LicenseSummaryPage.label.storageSize" ) )}
{/** Byte単位で受け取った値をGB単位で表示するため1000^3で割っている(小数点以下第三位まで表示で第四位で四捨五入) */} {( licenseSummaryInfo.storageSize / 1000 / 1000 / 1000 ).toFixed(3)} GB
{t( getTranslationID("LicenseSummaryPage.label.usedSize") )}
{/** Byte単位で受け取った値をGB単位で表示するため1000^3で割っている(小数点以下第三位まで表示で第四位で四捨五入) */} {( licenseSummaryInfo.usedSize / 1000 / 1000 / 1000 ).toFixed(3)} GB
{t( getTranslationID( "LicenseSummaryPage.label.storageAvailable" ) )}
{licenseSummaryInfo.isStorageAvailable && ( )} {!licenseSummaryInfo.isStorageAvailable && ( )}
)} ); }; LicenseSummary.defaultProps = { onReturn: undefined, }; export default LicenseSummary;