在這個 NextJS 應用程式中,有一個permissions.tsx看起來像這樣的檔案:
// @ts-nocheck
import { useState, useEffect } from 'react'
import { useSession } from 'next-auth/client'
function usePermissions() {
const [permissions, setPermissions] = useState(null)
const [session] = useSession()
// All permission types
const [quickStart, setQuickStart] = useState(false)
const [briefIntro, seBriefIntro] = useState(false)
const [cheatSheet, setCheatSheet] = useState(false)
const [totalClinics, setTotalClinics] = useState(false)
const [asthmaControl, setAsthmaControl] = useState(false)
const [revenueProjection, setRevenueProjection] = useState(false)
const [revenueStats, setRevenueStats] = useState(false)
const [addNewPatient, setAddNewPatient] = useState(false)
const [searchPatient, setSearchPatient] = useState(false)
const [permissionPublicUserId, setPermissionPublicUserId] = useState(false)
const [billablePatientsCounter, setBillablePatientsCounter] = useState(false)
useEffect(() => {
setPermissions(session?.user?.componentPermissions)
setQuickStart(allow('armadillo.mainView.quickStartGuide.section'))
seBriefIntro(allow('armadillo.mainView.aBriefIntroduction.section'))
setCheatSheet(allow('armadillo.mainView.accessTheCheatSheet.section'))
setTotalClinics(allow('armadillo.patients.thisWeek.InOfficeOnboards.counter'))
setAsthmaControl(allow('armadillo.mainView.stats.asthmaControl.section'))
setRevenueProjection(
allow('armadillo.mainView.stats.revenewProjection.section')
)
setRevenueStats(allow('armadillo.mainView.stats.revenewStats.section'))
setAddNewPatient(allow('armadillo.patients.addNewPatient.button'))
setPermissionPublicUserId(allow('armadillo.users.publicUserId.label'))
setBillablePatientsCounter(
allow('armadillo.patients.lastLogin.newBillablePatients.counter')
)
}, [])
const allow = (permission) =>
session?.user?.componentPermissions?.includes(permission) || false // Be determinant.
return {
permissions,
quickStart,
briefIntro,
cheatSheet,
totalClinics,
asthmaControl,
revenueProjection,
revenueStats,
addNewPatient,
searchPatient,
permissionPublicUserId,
billablePatientsCounter,
}
}
export default usePermissions
focus 的屬性是字串'armadillo.patients.lastLogin.newBillablePatients.counter'。顯然,此字串僅存在于具有可計費患者的帳戶中。所以我可以將它用作我的布林值,但不完全確定如何,我嘗試過的方法沒有奏效。
我試圖在另一個檔案中設定一個 if 條件,該檔案有一個useTimeout看起來像這樣的鉤子:
useTimeout(() => {
resetBillinSessionTimeout()
setIsIdle(true)
}, inactivityDelay)
因此,此超時彈出視窗在兩分鐘不活動后啟動,但僅適用于應該是醫生的用戶,對于其他用戶,它永遠不應該啟動此不活動模式,但確實如此。當我inactivityDelay用null不活動模式替換時,從未出現過,所以這就是我專注于那里的原因。
uj5u.com熱心網友回復:
我不確定我是否完全理解這個場景,但也許是這樣的:
useTimeout(() => {
resetBillinSessionTimeout()
setIsIdle(true)
}, billablePatientsCounter ? inactivityDelay : null)
僅為inactivityDelay計費患者設定。
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/403742.html
標籤:
