refactor: simplify database colums

This commit is contained in:
Mauricio Siu
2024-09-01 00:48:47 -06:00
parent 73efe0d0ed
commit 766b166bf2
10 changed files with 70 additions and 76 deletions

View File

@@ -47,7 +47,7 @@ const BitbucketProviderSchema = z.object({
})
.required(),
branch: z.string().min(1, "Branch is required"),
bitbucketProviderId: z.string().min(1, "Bitbucket Provider is required"),
bitbucketId: z.string().min(1, "Bitbucket Provider is required"),
});
type BitbucketProvider = z.infer<typeof BitbucketProviderSchema>;
@@ -71,14 +71,14 @@ export const SaveBitbucketProvider = ({ applicationId }: Props) => {
owner: "",
repo: "",
},
bitbucketProviderId: "",
bitbucketId: "",
branch: "",
},
resolver: zodResolver(BitbucketProviderSchema),
});
const repository = form.watch("repository");
const bitbucketProviderId = form.watch("bitbucketProviderId");
const bitbucketId = form.watch("bitbucketId");
const {
data: repositories,
@@ -86,7 +86,7 @@ export const SaveBitbucketProvider = ({ applicationId }: Props) => {
error,
isError,
} = api.gitProvider.getBitbucketRepositories.useQuery({
bitbucketProviderId,
bitbucketId,
});
const {
@@ -97,11 +97,10 @@ export const SaveBitbucketProvider = ({ applicationId }: Props) => {
{
owner: repository?.owner,
repo: repository?.repo,
bitbucketProviderId,
bitbucketId,
},
{
enabled:
!!repository?.owner && !!repository?.repo && !!bitbucketProviderId,
enabled: !!repository?.owner && !!repository?.repo && !!bitbucketId,
},
);
@@ -114,7 +113,7 @@ export const SaveBitbucketProvider = ({ applicationId }: Props) => {
owner: data.bitbucketOwner || "",
},
buildPath: data.bitbucketBuildPath || "/",
bitbucketProviderId: data.bitbucketProviderId || "",
bitbucketId: data.bitbucketId || "",
});
}
}, [form.reset, data, form]);
@@ -125,7 +124,7 @@ export const SaveBitbucketProvider = ({ applicationId }: Props) => {
bitbucketRepository: data.repository.repo,
bitbucketOwner: data.repository.owner,
bitbucketBuildPath: data.buildPath,
bitbucketProviderId: data.bitbucketProviderId,
bitbucketId: data.bitbucketId,
applicationId,
})
.then(async () => {
@@ -150,7 +149,7 @@ export const SaveBitbucketProvider = ({ applicationId }: Props) => {
<div className="grid md:grid-cols-2 gap-4">
<FormField
control={form.control}
name="bitbucketProviderId"
name="bitbucketId"
render={({ field }) => (
<FormItem className="md:col-span-2 flex flex-col">
<FormLabel>Bitbucket Account</FormLabel>
@@ -174,8 +173,8 @@ export const SaveBitbucketProvider = ({ applicationId }: Props) => {
<SelectContent>
{bitbucketProviders?.map((bitbucketProvider) => (
<SelectItem
key={bitbucketProvider.bitbucketProviderId}
value={bitbucketProvider.bitbucketProviderId}
key={bitbucketProvider.bitbucketId}
value={bitbucketProvider.bitbucketId}
>
{bitbucketProvider.gitProvider.name}
</SelectItem>

View File

@@ -46,7 +46,7 @@ const GithubProviderSchema = z.object({
})
.required(),
branch: z.string().min(1, "Branch is required"),
githubProviderId: z.string().min(1, "Github Provider is required"),
githubId: z.string().min(1, "Github Provider is required"),
});
type GithubProvider = z.infer<typeof GithubProviderSchema>;
@@ -69,18 +69,18 @@ export const SaveGithubProvider = ({ applicationId }: Props) => {
owner: "",
repo: "",
},
githubProviderId: "",
githubId: "",
branch: "",
},
resolver: zodResolver(GithubProviderSchema),
});
const repository = form.watch("repository");
const githubProviderId = form.watch("githubProviderId");
const githubId = form.watch("githubId");
const { data: repositories, isLoading: isLoadingRepositories } =
api.gitProvider.getRepositories.useQuery({
githubProviderId,
githubId,
});
const {
@@ -91,10 +91,10 @@ export const SaveGithubProvider = ({ applicationId }: Props) => {
{
owner: repository?.owner,
repo: repository?.repo,
githubProviderId,
githubId,
},
{
enabled: !!repository?.owner && !!repository?.repo && !!githubProviderId,
enabled: !!repository?.owner && !!repository?.repo && !!githubId,
},
);
@@ -107,7 +107,7 @@ export const SaveGithubProvider = ({ applicationId }: Props) => {
owner: data.owner || "",
},
buildPath: data.buildPath || "/",
githubProviderId: data.githubProviderId || "",
githubId: data.githubId || "",
});
}
}, [form.reset, data, form]);
@@ -119,7 +119,7 @@ export const SaveGithubProvider = ({ applicationId }: Props) => {
applicationId,
owner: data.repository.owner,
buildPath: data.buildPath,
githubProviderId: data.githubProviderId,
githubId: data.githubId,
})
.then(async () => {
toast.success("Service Provided Saved");
@@ -140,7 +140,7 @@ export const SaveGithubProvider = ({ applicationId }: Props) => {
<div className="grid md:grid-cols-2 gap-4">
<FormField
control={form.control}
name="githubProviderId"
name="githubId"
render={({ field }) => (
<FormItem className="md:col-span-2 flex flex-col">
<FormLabel>Github Account</FormLabel>
@@ -164,8 +164,8 @@ export const SaveGithubProvider = ({ applicationId }: Props) => {
<SelectContent>
{githubProviders?.map((githubProvider) => (
<SelectItem
key={githubProvider.githubProviderId}
value={githubProvider.githubProviderId}
key={githubProvider.githubId}
value={githubProvider.githubId}
>
{githubProvider.gitProvider.name}
</SelectItem>

View File

@@ -47,7 +47,7 @@ const GitlabProviderSchema = z.object({
})
.required(),
branch: z.string().min(1, "Branch is required"),
gitlabProviderId: z.string().min(1, "Gitlab Provider is required"),
gitlabId: z.string().min(1, "Gitlab Provider is required"),
});
type GitlabProvider = z.infer<typeof GitlabProviderSchema>;
@@ -70,21 +70,21 @@ export const SaveGitlabProvider = ({ applicationId }: Props) => {
owner: "",
repo: "",
},
gitlabProviderId: "",
gitlabId: "",
branch: "",
},
resolver: zodResolver(GitlabProviderSchema),
});
const repository = form.watch("repository");
const gitlabProviderId = form.watch("gitlabProviderId");
const gitlabId = form.watch("gitlabId");
const {
data: repositories,
isLoading: isLoadingRepositories,
error,
} = api.gitProvider.getGitlabRepositories.useQuery({
gitlabProviderId,
gitlabId,
});
const {
@@ -95,10 +95,10 @@ export const SaveGitlabProvider = ({ applicationId }: Props) => {
{
owner: repository?.owner,
repo: repository?.repo,
gitlabProviderId: gitlabProviderId,
gitlabId: gitlabId,
},
{
enabled: !!repository?.owner && !!repository?.repo && !!gitlabProviderId,
enabled: !!repository?.owner && !!repository?.repo && !!gitlabId,
},
);
@@ -111,7 +111,7 @@ export const SaveGitlabProvider = ({ applicationId }: Props) => {
owner: data.gitlabOwner || "",
},
buildPath: data.gitlabBuildPath || "/",
gitlabProviderId: data.gitlabProviderId || "",
gitlabId: data.gitlabId || "",
});
}
}, [form.reset, data, form]);
@@ -122,7 +122,7 @@ export const SaveGitlabProvider = ({ applicationId }: Props) => {
gitlabRepository: data.repository.repo,
gitlabOwner: data.repository.owner,
gitlabBuildPath: data.buildPath,
gitlabProviderId: data.gitlabProviderId,
gitlabId: data.gitlabId,
applicationId,
})
.then(async () => {
@@ -145,7 +145,7 @@ export const SaveGitlabProvider = ({ applicationId }: Props) => {
<div className="grid md:grid-cols-2 gap-4">
<FormField
control={form.control}
name="gitlabProviderId"
name="gitlabId"
render={({ field }) => (
<FormItem className="md:col-span-2 flex flex-col">
<FormLabel>Gitlab Account</FormLabel>
@@ -169,8 +169,8 @@ export const SaveGitlabProvider = ({ applicationId }: Props) => {
<SelectContent>
{gitlabProviders?.map((gitlabProvider) => (
<SelectItem
key={gitlabProvider.gitlabProviderId}
value={gitlabProvider.gitlabProviderId}
key={gitlabProvider.gitlabId}
value={gitlabProvider.gitlabId}
>
{gitlabProvider.gitProvider.name}
</SelectItem>