(action: "start" | "verify" | "cancel" | "retry" | "lock")
| 118 | }, [status]); |
| 119 | |
| 120 | const act = async (action: "start" | "verify" | "cancel" | "retry" | "lock") => { |
| 121 | const signal = controller.current?.signal; |
| 122 | if (!signal || signal.aborted || busy) return; |
| 123 | setBusy(true); |
| 124 | setError(null); |
| 125 | if (action === "lock") { |
| 126 | await run(request("/lock", decodeCanceled, {}), signal, () => window.location.reload()); |
| 127 | } else if (action === "start") { |
| 128 | await run(request("/start", decodeChallenge, {}), signal, (next) => { |
| 129 | setChallenge(next); |
| 130 | setCode(""); |
| 131 | }); |
| 132 | } else if (action === "verify") { |
| 133 | await run(request("/verify", decodeVerified, { code }), signal, () => { |
| 134 | setChallenge(null); |
| 135 | setCode(""); |
| 136 | // Reload clears cached admin requests and the enrollment secret while |
| 137 | // retaining the current organization's URL. |
| 138 | window.location.reload(); |
| 139 | }); |
| 140 | } else if (action === "cancel") { |
| 141 | await run(request("/cancel", decodeCanceled, {}), signal, () => { |
| 142 | setChallenge(null); |
| 143 | setCode(""); |
| 144 | }); |
| 145 | } else { |
| 146 | await run(request("", decodeStatus), signal, setStatus); |
| 147 | } |
| 148 | if (!signal.aborted) setBusy(false); |
| 149 | }; |
| 150 | |
| 151 | if (status?.state === "verified") |
| 152 | return ( |
no test coverage detected