Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit3b07068

Browse files
committed
Break out useExternalAuth hook
We will use this on the tasks page.
1 parentf1cca03 commit3b07068

File tree

5 files changed

+54
-56
lines changed

5 files changed

+54
-56
lines changed

‎site/src/hooks/useExternalAuth.ts

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import{templateVersionExternalAuth}from"api/queries/templates";
2+
import{useCallback,useEffect,useState}from"react";
3+
import{useQuery}from"react-query";
4+
5+
exporttypeExternalAuthPollingState="idle"|"polling"|"abandoned";
6+
7+
exportconstuseExternalAuth=(versionId:string|undefined)=>{
8+
const[externalAuthPollingState,setExternalAuthPollingState]=
9+
useState<ExternalAuthPollingState>("idle");
10+
11+
conststartPollingExternalAuth=useCallback(()=>{
12+
setExternalAuthPollingState("polling");
13+
},[]);
14+
15+
const{data:externalAuth,isPending:isLoadingExternalAuth}=useQuery({
16+
...templateVersionExternalAuth(versionId??""),
17+
enabled:!!versionId,
18+
refetchInterval:externalAuthPollingState==="polling" ?1000 :false,
19+
});
20+
21+
constallSignedIn=externalAuth?.every((it)=>it.authenticated);
22+
23+
useEffect(()=>{
24+
if(allSignedIn){
25+
setExternalAuthPollingState("idle");
26+
return;
27+
}
28+
29+
if(externalAuthPollingState!=="polling"){
30+
return;
31+
}
32+
33+
// Poll for a maximum of one minute
34+
constquitPolling=setTimeout(
35+
()=>setExternalAuthPollingState("abandoned"),
36+
60_000,
37+
);
38+
return()=>{
39+
clearTimeout(quitPolling);
40+
};
41+
},[externalAuthPollingState,allSignedIn]);
42+
43+
return{
44+
startPollingExternalAuth,
45+
externalAuth,
46+
externalAuthPollingState,
47+
isLoadingExternalAuth,
48+
};
49+
};

‎site/src/pages/CreateWorkspacePage/CreateWorkspacePage.tsx

Lines changed: 1 addition & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import { checkAuthorization } from "api/queries/authCheck";
44
import{
55
richParameters,
66
templateByName,
7-
templateVersionExternalAuth,
87
templateVersionPresets,
98
}from"api/queries/templates";
109
import{autoCreateWorkspace,createWorkspace}from"api/queries/workspaces";
@@ -17,6 +16,7 @@ import type {
1716
import{Loader}from"components/Loader/Loader";
1817
import{useAuthenticated}from"hooks";
1918
import{useEffectEvent}from"hooks/hookPolyfills";
19+
import{useExternalAuth}from"hooks/useExternalAuth";
2020
import{useDashboard}from"modules/dashboard/useDashboard";
2121
import{generateWorkspaceName}from"modules/workspaces/generateWorkspaceName";
2222
import{typeFC,useCallback,useEffect,useRef,useState}from"react";
@@ -35,8 +35,6 @@ import {
3535
constcreateWorkspaceModes=["form","auto","duplicate"]asconst;
3636
exporttypeCreateWorkspaceMode=(typeofcreateWorkspaceModes)[number];
3737

38-
exporttypeExternalAuthPollingState="idle"|"polling"|"abandoned";
39-
4038
constCreateWorkspacePage:FC=()=>{
4139
const{organization:organizationName="default",template:templateName}=
4240
useParams()as{organization?:string;template:string};
@@ -237,50 +235,6 @@ const CreateWorkspacePage: FC = () => {
237235
);
238236
};
239237

240-
constuseExternalAuth=(versionId:string|undefined)=>{
241-
const[externalAuthPollingState,setExternalAuthPollingState]=
242-
useState<ExternalAuthPollingState>("idle");
243-
244-
conststartPollingExternalAuth=useCallback(()=>{
245-
setExternalAuthPollingState("polling");
246-
},[]);
247-
248-
const{data:externalAuth,isPending:isLoadingExternalAuth}=useQuery({
249-
...templateVersionExternalAuth(versionId??""),
250-
enabled:!!versionId,
251-
refetchInterval:externalAuthPollingState==="polling" ?1000 :false,
252-
});
253-
254-
constallSignedIn=externalAuth?.every((it)=>it.authenticated);
255-
256-
useEffect(()=>{
257-
if(allSignedIn){
258-
setExternalAuthPollingState("idle");
259-
return;
260-
}
261-
262-
if(externalAuthPollingState!=="polling"){
263-
return;
264-
}
265-
266-
// Poll for a maximum of one minute
267-
constquitPolling=setTimeout(
268-
()=>setExternalAuthPollingState("abandoned"),
269-
60_000,
270-
);
271-
return()=>{
272-
clearTimeout(quitPolling);
273-
};
274-
},[externalAuthPollingState,allSignedIn]);
275-
276-
return{
277-
startPollingExternalAuth,
278-
externalAuth,
279-
externalAuthPollingState,
280-
isLoadingExternalAuth,
281-
};
282-
};
283-
284238
constgetAutofillParameters=(
285239
urlSearchParams:URLSearchParams,
286240
userParameters:UserParameter[],

‎site/src/pages/CreateWorkspacePage/CreateWorkspacePageView.tsx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import { Stack } from "components/Stack/Stack";
2727
import{Switch}from"components/Switch/Switch";
2828
import{UserAutocomplete}from"components/UserAutocomplete/UserAutocomplete";
2929
import{typeFormikContextType,useFormik}from"formik";
30+
importtype{ExternalAuthPollingState}from"hooks/useExternalAuth";
3031
import{generateWorkspaceName}from"modules/workspaces/generateWorkspaceName";
3132
import{typeFC,useCallback,useEffect,useMemo,useState}from"react";
3233
import{
@@ -40,10 +41,7 @@ import {
4041
useValidationSchemaForRichParameters,
4142
}from"utils/richParameters";
4243
import*asYupfrom"yup";
43-
importtype{
44-
CreateWorkspaceMode,
45-
ExternalAuthPollingState,
46-
}from"./CreateWorkspacePage";
44+
importtype{CreateWorkspaceMode}from"./CreateWorkspacePage";
4745
import{ExternalAuthButton}from"./ExternalAuthButton";
4846
importtype{CreateWorkspacePermissions}from"./permissions";
4947

‎site/src/pages/CreateWorkspacePage/CreateWorkspacePageViewExperimental.tsx

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,7 @@ import { docs } from "utils/docs";
4747
import{nameValidator}from"utils/formUtils";
4848
importtype{AutofillBuildParameter}from"utils/richParameters";
4949
import*asYupfrom"yup";
50-
importtype{
51-
CreateWorkspaceMode,
52-
ExternalAuthPollingState,
53-
}from"./CreateWorkspacePage";
50+
importtype{CreateWorkspaceMode}from"./CreateWorkspacePage";
5451
import{ExternalAuthButton}from"./ExternalAuthButton";
5552
importtype{CreateWorkspacePermissions}from"./permissions";
5653

‎site/src/pages/UserSettingsPage/ExternalAuthPage/ExternalAuthPageView.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ import { Loader } from "components/Loader/Loader";
2727
import{Spinner}from"components/Spinner/Spinner";
2828
import{Stack}from"components/Stack/Stack";
2929
import{TableEmpty}from"components/TableEmpty/TableEmpty";
30+
importtype{ExternalAuthPollingState}from"hooks/useExternalAuth";
3031
import{EllipsisVertical}from"lucide-react";
31-
importtype{ExternalAuthPollingState}from"pages/CreateWorkspacePage/CreateWorkspacePage";
3232
import{typeFC,useCallback,useEffect,useState}from"react";
3333
import{useQuery}from"react-query";
3434

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp