misc: addressed first set of review comments

This commit is contained in:
Sheen Capadngan
2025-05-22 00:22:49 +08:00
parent 77b42836e7
commit 77de085ffc
32 changed files with 339 additions and 252 deletions
+1 -1
View File
@@ -12,8 +12,8 @@ export {
useUpdateUnifiedCa
} from "./mutations";
export {
useGetCa,
useGetCaById,
useGetCaByTypeAndId,
useGetCaCert,
useGetCaCerts,
useGetCaCertTemplates,
+11 -8
View File
@@ -26,15 +26,13 @@ import {
export const useUpdateUnifiedCa = () => {
const queryClient = useQueryClient();
return useMutation<TUnifiedCertificateAuthority, object, TUpdateUnifiedCertificateAuthorityDTO>({
mutationFn: async ({ id, ...body }) => {
const {
data: { certificateAuthority }
} = await apiRequest.patch<{ certificateAuthority: TUnifiedCertificateAuthority }>(
`/api/v1/pki/ca/${body.type}/${id}`,
mutationFn: async ({ caName, ...body }) => {
const { data } = await apiRequest.patch<TUnifiedCertificateAuthority>(
`/api/v1/pki/ca/${body.type}/${caName}`,
body
);
return certificateAuthority;
return data;
},
onSuccess: ({ projectId, type }) => {
queryClient.invalidateQueries({
@@ -65,11 +63,16 @@ export const useCreateUnifiedCa = () => {
export const useDeleteUnifiedCa = () => {
const queryClient = useQueryClient();
return useMutation<TUnifiedCertificateAuthority, object, TDeleteUnifiedCertificateAuthorityDTO>({
mutationFn: async ({ caId, type }) => {
mutationFn: async ({ caName, type, projectId }) => {
const {
data: { certificateAuthority }
} = await apiRequest.delete<{ certificateAuthority: TUnifiedCertificateAuthority }>(
`/api/v1/pki/ca/${type}/${caId}`
`/api/v1/pki/ca/${type}/${caName}`,
{
data: {
projectId
}
}
);
return certificateAuthority;
},
+19 -13
View File
@@ -8,7 +8,7 @@ import { TCertificateAuthority, TUnifiedCertificateAuthority } from "./types";
export const caKeys = {
getCaById: (caId: string) => [{ caId }, "ca"],
getCaByTypeAndId: (type: CaType, caId: string) => [{ type, caId }, "ca"],
getCaByNameAndProjectId: (caName: string, projectId: string) => [{ caName, projectId }, "ca"],
listCasByTypeAndProjectId: (type: CaType, projectId: string) => [{ type, projectId }, "cas"],
listCasByProjectId: (projectId: string) => [{ projectId }, "cas"],
getCaCerts: (caId: string) => [{ caId }, "ca-cert"],
@@ -20,18 +20,24 @@ export const caKeys = {
getCaEstConfig: (caId: string) => [{ caId }, "ca-est-config"]
};
export const useGetCaByTypeAndId = (type: CaType, caId: string) => {
export const useGetCa = ({
caName,
projectId,
type
}: {
caName: string;
projectId: string;
type: CaType;
}) => {
return useQuery({
queryKey: caKeys.getCaByTypeAndId(type, caId),
queryKey: caKeys.getCaByNameAndProjectId(caName, projectId),
queryFn: async () => {
const {
data: { certificateAuthority }
} = await apiRequest.get<{ certificateAuthority: TUnifiedCertificateAuthority }>(
`/api/v1/pki/ca/${type}/${caId}`
const { data } = await apiRequest.get<TUnifiedCertificateAuthority>(
`/api/v1/pki/ca/${type}/${caName}?projectId=${projectId}`
);
return certificateAuthority;
return data;
},
enabled: Boolean(caId)
enabled: Boolean(caName && projectId && type)
});
};
@@ -39,11 +45,11 @@ export const useListCasByTypeAndProjectId = (type: CaType, projectId: string) =>
return useQuery({
queryKey: caKeys.listCasByTypeAndProjectId(type, projectId),
queryFn: async () => {
const { data } = await apiRequest.get<{
certificateAuthorities: TUnifiedCertificateAuthority[];
}>(`/api/v1/pki/ca/${type}?projectId=${projectId}`);
const { data } = await apiRequest.get<TUnifiedCertificateAuthority[]>(
`/api/v1/pki/ca/${type}?projectId=${projectId}`
);
return data.certificateAuthorities;
return data;
}
});
};
+5 -4
View File
@@ -7,7 +7,7 @@ export type TAcmeCertificateAuthority = {
type: CaType.ACME;
status: CaStatus;
name: string;
disableDirectIssuance: boolean;
enableDirectIssuance: boolean;
configuration: {
dnsAppConnectionId: string;
dnsProviderConfig: {
@@ -25,7 +25,7 @@ export type TInternalCertificateAuthority = {
type: CaType.INTERNAL;
status: CaStatus;
name: string;
disableDirectIssuance: boolean;
enableDirectIssuance: boolean;
configuration: {
type: InternalCaType;
friendlyName?: string;
@@ -52,12 +52,13 @@ export type TUnifiedCertificateAuthority =
export type TCreateUnifiedCertificateAuthorityDTO = Omit<TUnifiedCertificateAuthority, "id">;
export type TUpdateUnifiedCertificateAuthorityDTO = Partial<TUnifiedCertificateAuthority> & {
id: string;
caName: string;
projectId: string;
type: CaType;
};
export type TDeleteUnifiedCertificateAuthorityDTO = {
caId: string;
caName: string;
type: CaType;
projectId: string;
};
@@ -23,7 +23,7 @@ import {
CaStatus,
CaType,
useCreateUnifiedCa,
useGetCaByTypeAndId,
useGetCa,
useUpdateUnifiedCa
} from "@app/hooks/api/ca";
import { UsePopUpState } from "@app/hooks/usePopUp";
@@ -35,7 +35,7 @@ const schema = z
name: slugSchema({
field: "Name"
}),
disableDirectIssuance: z.boolean(),
enableDirectIssuance: z.boolean(),
status: z.nativeEnum(CaStatus),
configuration: z.object({
dnsAppConnection: z.object({
@@ -65,10 +65,11 @@ const caTypes = [{ label: "ACME", value: CaType.ACME }];
export const ExternalCaModal = ({ popUp, handlePopUpToggle }: Props) => {
const { currentWorkspace } = useWorkspace();
const { data: ca } = useGetCaByTypeAndId(
(popUp?.ca?.data as { type: CaType })?.type || "",
(popUp?.ca?.data as { caId: string })?.caId || ""
);
const { data: ca } = useGetCa({
caName: (popUp?.ca?.data as { name: string })?.name || "",
projectId: currentWorkspace?.id || "",
type: (popUp?.ca?.data as { type: CaType })?.type || ""
});
const { mutateAsync: createMutateAsync } = useCreateUnifiedCa();
const { mutateAsync: updateMutateAsync } = useUpdateUnifiedCa();
@@ -85,7 +86,7 @@ export const ExternalCaModal = ({ popUp, handlePopUpToggle }: Props) => {
type: CaType.ACME,
name: "",
status: CaStatus.ACTIVE,
disableDirectIssuance: false,
enableDirectIssuance: true,
configuration: {
dnsAppConnection: {
id: "",
@@ -122,7 +123,7 @@ export const ExternalCaModal = ({ popUp, handlePopUpToggle }: Props) => {
type: ca.type,
name: ca.name,
status: ca.status,
disableDirectIssuance: ca.disableDirectIssuance,
enableDirectIssuance: ca.enableDirectIssuance,
configuration: {
dnsAppConnection: {
id: ca.configuration.dnsAppConnectionId,
@@ -142,7 +143,7 @@ export const ExternalCaModal = ({ popUp, handlePopUpToggle }: Props) => {
type: CaType.ACME,
name: "",
status: CaStatus.ACTIVE,
disableDirectIssuance: false,
enableDirectIssuance: true,
configuration: {
dnsAppConnection: {
id: "",
@@ -162,7 +163,7 @@ export const ExternalCaModal = ({ popUp, handlePopUpToggle }: Props) => {
const onFormSubmit = async ({
type,
name,
disableDirectIssuance,
enableDirectIssuance,
status,
configuration
}: FormData) => {
@@ -171,12 +172,12 @@ export const ExternalCaModal = ({ popUp, handlePopUpToggle }: Props) => {
if (ca && type !== CaType.INTERNAL) {
await updateMutateAsync({
id: ca.id,
caName: ca.name,
projectId: currentWorkspace.id,
name,
type,
status,
disableDirectIssuance,
enableDirectIssuance,
configuration: {
...configuration,
dnsAppConnectionId: configuration.dnsAppConnection.id
@@ -188,7 +189,7 @@ export const ExternalCaModal = ({ popUp, handlePopUpToggle }: Props) => {
name,
type,
status,
disableDirectIssuance,
enableDirectIssuance,
configuration: {
...configuration,
dnsAppConnectionId: configuration.dnsAppConnection.id
@@ -369,7 +370,7 @@ export const ExternalCaModal = ({ popUp, handlePopUpToggle }: Props) => {
)}
<Controller
control={control}
name="disableDirectIssuance"
name="enableDirectIssuance"
render={({ field, fieldState: { error } }) => {
return (
<FormControl isError={Boolean(error)} errorText={error?.message} className="my-8">
@@ -378,7 +379,7 @@ export const ExternalCaModal = ({ popUp, handlePopUpToggle }: Props) => {
onCheckedChange={(value) => field.onChange(value)}
isChecked={field.value}
>
<p className="w-full">Disable Direct Issuance</p>
<p className="w-full">Enable Direct Issuance</p>
</Switch>
</FormControl>
);
@@ -24,11 +24,11 @@ export const ExternalCaSection = () => {
"upgradePlan"
] as const);
const onRemoveCaSubmit = async (caId: string, type: CaType) => {
const onRemoveCaSubmit = async (caName: string, type: CaType) => {
try {
if (!currentWorkspace?.id) return;
await deleteCa({ caId, type, projectId: currentWorkspace.id });
await deleteCa({ caName, type, projectId: currentWorkspace.id });
createNotification({
text: "Successfully deleted CA",
@@ -45,18 +45,18 @@ export const ExternalCaSection = () => {
};
const onUpdateCaStatus = async ({
caId,
name,
type,
status
}: {
caId: string;
name: string;
type: CaType;
status: CaStatus;
}) => {
try {
if (!currentWorkspace?.slug) return;
await updateCa({ id: caId, type, status });
await updateCa({ caName: name, type, status, projectId: currentWorkspace.id });
createNotification({
text: `Successfully ${status === CaStatus.ACTIVE ? "enabled" : "disabled"} CA`,
@@ -105,7 +105,7 @@ export const ExternalCaSection = () => {
deleteKey="confirm"
onDeleteApproved={() =>
onRemoveCaSubmit(
(popUp?.deleteCa?.data as { caId: string })?.caId,
(popUp?.deleteCa?.data as { name: string })?.name,
(popUp?.deleteCa?.data as { type: CaType })?.type
)
}
@@ -127,7 +127,7 @@ export const ExternalCaSection = () => {
deleteKey="confirm"
onDeleteApproved={() =>
onUpdateCaStatus(
popUp?.caStatus?.data as { caId: string; type: CaType; status: CaStatus }
popUp?.caStatus?.data as { name: string; type: CaType; status: CaStatus }
)
}
/>
@@ -35,7 +35,7 @@ type Props = {
handlePopUpOpen: (
popUpName: keyof UsePopUpState<["ca", "deleteCa", "caStatus", "upgradePlan"]>,
data?: {
caId?: string;
name?: string;
type?: CaType;
status?: CaStatus;
description?: string;
@@ -71,7 +71,7 @@ export const ExternalCaTable = ({ handlePopUpOpen }: Props) => {
key={`ca-${ca.id}`}
onClick={() => {
handlePopUpOpen("ca", {
caId: ca.id,
name: ca.name,
type: ca.type
});
}}
@@ -105,7 +105,7 @@ export const ExternalCaTable = ({ handlePopUpOpen }: Props) => {
onClick={(e) => {
e.stopPropagation();
handlePopUpOpen("ca", {
caId: ca.id,
name: ca.name,
type: ca.type
});
}}
@@ -130,7 +130,7 @@ export const ExternalCaTable = ({ handlePopUpOpen }: Props) => {
onClick={(e) => {
e.stopPropagation();
handlePopUpOpen("caStatus", {
caId: ca.id,
name: ca.name,
type: ca.type,
status:
ca.status === CaStatus.ACTIVE
@@ -158,7 +158,7 @@ export const ExternalCaTable = ({ handlePopUpOpen }: Props) => {
onClick={(e) => {
e.stopPropagation();
handlePopUpOpen("deleteCa", {
caId: ca.id,
name: ca.name,
type: ca.type
});
}}