-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: Migrate useSelfHostedHasAdmins to TS Query V5 (#3579)
- Loading branch information
1 parent
753f06c
commit be9490c
Showing
7 changed files
with
102 additions
and
84 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 24 additions & 11 deletions
35
...elfHosted/useSelfHostedHasAdmins.test.tsx → ...ted/SelfHostedHasAdminsQueryOpts.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import { | ||
keepPreviousData, | ||
queryOptions as queryOptionsV5, | ||
} from '@tanstack/react-queryV5' | ||
import { z } from 'zod' | ||
|
||
import Api from 'shared/api' | ||
import { rejectNetworkError } from 'shared/api/helpers' | ||
|
||
export const HasAdminsSchema = z.object({ | ||
config: z | ||
.object({ | ||
hasAdmins: z.boolean().nullable(), | ||
}) | ||
.nullable(), | ||
}) | ||
|
||
const query = `query HasAdmins { config { hasAdmins } }` | ||
|
||
interface SelfHostedHasAdminsQueryArgs { | ||
provider: string | ||
} | ||
|
||
export const SelfHostedHasAdminsQueryOpts = ({ | ||
provider, | ||
}: SelfHostedHasAdminsQueryArgs) => { | ||
return queryOptionsV5({ | ||
queryKey: ['HasAdmins', provider], | ||
queryFn: () => | ||
Api.graphql({ | ||
provider, | ||
query, | ||
}).then((res) => { | ||
const parsedRes = HasAdminsSchema.safeParse(res?.data) | ||
|
||
if (!parsedRes.success) { | ||
return rejectNetworkError({ | ||
status: 404, | ||
data: {}, | ||
dev: 'SelfHostedHasAdminsQueryOpts - 404 schema parsing failed', | ||
error: parsedRes.error, | ||
}) | ||
} | ||
|
||
return !!parsedRes?.data?.config?.hasAdmins | ||
}), | ||
// this is how TSQuery V5 handles keepPreviousData | ||
placeholderData: keepPreviousData, | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
export * from './useSelfHostedCurrentUser' | ||
export * from './useSelfHostedSeatsConfig' | ||
export * from './useSelfHostedHasAdmins' | ||
export * from './useSelfHostedSeatsAndLicense' |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters