import { useState, useEffect } from 'react'; export type DrApproverState = 'loading' | 'yes' | 'no'; /** * True when the current session user has the **DR Approver** role (via asset_lite API). */ export function useDrApproverRole(): DrApproverState { const [state, setState] = useState('loading'); useEffect(() => { let cancelled = false; (async () => { try { const res = await fetch('/api/method/asset_lite.api.user_roles.check_has_role', { method: 'POST', headers: { 'Content-Type': 'application/json' }, credentials: 'include', body: JSON.stringify({ roles: 'DR Approver' }), }); const data = await res.json(); if (cancelled) return; setState(data.message?.has_role ? 'yes' : 'no'); } catch { if (!cancelled) setState('no'); } })(); return () => { cancelled = true; }; }, []); return state; }