diff --git a/packages/slice-machine/src/features/git/useGitRepos.ts b/packages/slice-machine/src/features/git/useGitRepos.ts index ca445d3723..22ede88d29 100644 --- a/packages/slice-machine/src/features/git/useGitRepos.ts +++ b/packages/slice-machine/src/features/git/useGitRepos.ts @@ -1,16 +1,26 @@ import { useRequest } from "@prismicio/editor-support/Suspense"; import { managerClient } from "@src/managerClient"; -type UseGitReposArgs = Parameters[0]; - -const getGitRepos = async (args?: UseGitReposArgs) => { - if (!args) { +async function getGitRepos( + provider?: "gitHub", + owner?: string, + query?: string, + page?: number, +) { + if (provider === undefined || owner === undefined) { return; } - return await managerClient.git.fetchRepos(args); -}; + return await managerClient.git.fetchRepos({ provider, owner, query, page }); +} -export const useGitRepos = (args?: UseGitReposArgs) => { - return useRequest(getGitRepos, [args]); +export const useGitRepos = ( + args?: Parameters[0], +) => { + return useRequest(getGitRepos, [ + args?.provider, + args?.owner, + args?.query, + args?.page, + ]); }; diff --git a/packages/slice-machine/src/features/git/useHasWriteAPIToken.ts b/packages/slice-machine/src/features/git/useHasWriteAPIToken.ts index a72e4d4485..0a82dfe173 100644 --- a/packages/slice-machine/src/features/git/useHasWriteAPIToken.ts +++ b/packages/slice-machine/src/features/git/useHasWriteAPIToken.ts @@ -2,22 +2,33 @@ import { useRequest } from "@prismicio/editor-support/Suspense"; import { useSliceMachineConfig } from "@src/hooks/useSliceMachineConfig"; import { managerClient } from "@src/managerClient"; -import { GitRepoSpecifier, PrismicRepoSpecifier } from "./types"; +import { GitRepoSpecifier } from "./types"; -export const getHasWriteAPIToken = async (args: { - prismic: PrismicRepoSpecifier; - git: GitRepoSpecifier; -}): Promise => { - return await managerClient.git.checkHasWriteAPIToken(args); +export const getHasWriteAPIToken = async ( + prismicDomain: string, + gitProvider: "gitHub", + gitOwner: string, + gitName: string, +): Promise => { + return await managerClient.git.checkHasWriteAPIToken({ + prismic: { + domain: prismicDomain, + }, + git: { + provider: gitProvider, + owner: gitOwner, + name: gitName, + }, + }); }; export const useHasWriteAPIToken = (args: { git: GitRepoSpecifier }) => { const [config] = useSliceMachineConfig(); return useRequest(getHasWriteAPIToken, [ - { - prismic: { domain: config.repositoryName }, - git: args.git, - }, + config.repositoryName, + args.git.provider, + args.git.owner, + args.git.name, ]); }; diff --git a/packages/slice-machine/src/features/git/useLinkedGitRepos.ts b/packages/slice-machine/src/features/git/useLinkedGitRepos.ts index 2daf5bcf45..d715718a1a 100644 --- a/packages/slice-machine/src/features/git/useLinkedGitRepos.ts +++ b/packages/slice-machine/src/features/git/useLinkedGitRepos.ts @@ -2,8 +2,6 @@ import { useRequest } from "@prismicio/editor-support/Suspense"; import { useSliceMachineConfig } from "@src/hooks/useSliceMachineConfig"; import { managerClient } from "@src/managerClient"; -import { PrismicRepoSpecifier } from "./types"; - type UseLinkedGitReposReturnType = | { repos: Awaited< @@ -12,11 +10,13 @@ type UseLinkedGitReposReturnType = } | { error: unknown }; -export const getLinkedGitRepos = async (args: { - prismic: PrismicRepoSpecifier; -}): Promise => { +export const getLinkedGitRepos = async ( + prismicDomain: string, +): Promise => { try { - const repos = await managerClient.git.fetchLinkedRepos(args); + const repos = await managerClient.git.fetchLinkedRepos({ + prismic: { domain: prismicDomain }, + }); return { repos }; } catch (error) { @@ -27,7 +27,5 @@ export const getLinkedGitRepos = async (args: { export const useLinkedGitRepos = () => { const [config] = useSliceMachineConfig(); - return useRequest(getLinkedGitRepos, [ - { prismic: { domain: config.repositoryName } }, - ]); + return useRequest(getLinkedGitRepos, [config.repositoryName]); }; diff --git a/packages/slice-machine/src/features/git/useLinkedGitReposActions.ts b/packages/slice-machine/src/features/git/useLinkedGitReposActions.ts index fd4da2a611..7b86ab9bc0 100644 --- a/packages/slice-machine/src/features/git/useLinkedGitReposActions.ts +++ b/packages/slice-machine/src/features/git/useLinkedGitReposActions.ts @@ -16,9 +16,7 @@ export const useLinkedGitReposActions = () => { git, }); - revalidateData(getLinkedGitRepos, [ - { prismic: { domain: config.repositoryName } }, - ]); + revalidateData(getLinkedGitRepos, [config.repositoryName]); }, unlinkRepo: async (git: GitRepoSpecifier) => { await managerClient.git.unlinkRepo({ @@ -26,14 +24,12 @@ export const useLinkedGitReposActions = () => { git, }); - revalidateData(getLinkedGitRepos, [ - { prismic: { domain: config.repositoryName } }, - ]); + revalidateData(getLinkedGitRepos, [config.repositoryName]); revalidateData(getHasWriteAPIToken, [ - { - prismic: { domain: config.repositoryName }, - git, - }, + config.repositoryName, + git.provider, + git.owner, + git.name, ]); }, }; diff --git a/packages/slice-machine/src/features/git/useWriteAPITokenActions.ts b/packages/slice-machine/src/features/git/useWriteAPITokenActions.ts index bcacad089b..956dffb2a3 100644 --- a/packages/slice-machine/src/features/git/useWriteAPITokenActions.ts +++ b/packages/slice-machine/src/features/git/useWriteAPITokenActions.ts @@ -17,10 +17,10 @@ export const useWriteAPITokenActions = (args: { git: GitRepoSpecifier }) => { }); revalidateData(getHasWriteAPIToken, [ - { - prismic: { domain: config.repositoryName }, - git: args.git, - }, + config.repositoryName, + args.git.provider, + args.git.owner, + args.git.name, ]); }, deleteToken: async () => { @@ -30,10 +30,10 @@ export const useWriteAPITokenActions = (args: { git: GitRepoSpecifier }) => { }); revalidateData(getHasWriteAPIToken, [ - { - prismic: { domain: config.repositoryName }, - git: args.git, - }, + config.repositoryName, + args.git.provider, + args.git.owner, + args.git.name, ]); }, };