wip: Start work on submitting the cert
This commit is contained in:
parent
651c205656
commit
22eae92cba
2 changed files with 48 additions and 45 deletions
|
@ -2,7 +2,11 @@
|
||||||
import { ref, useId, useTemplateRef } from "vue";
|
import { ref, useId, useTemplateRef } from "vue";
|
||||||
import CountryListItem from "./CountryListItem.vue";
|
import CountryListItem from "./CountryListItem.vue";
|
||||||
import { type Country, getAvailableCountries, userCountry } from "../utils/countries.ts";
|
import { type Country, getAvailableCountries, userCountry } from "../utils/countries.ts";
|
||||||
import { fetchClient, type Schemas } from "../plugins/client.ts";
|
import { type Schemas } from "../plugins/client.ts";
|
||||||
|
|
||||||
|
const { isSubmitting } = defineProps({
|
||||||
|
isSubmitting: Boolean,
|
||||||
|
})
|
||||||
|
|
||||||
const formModel = ref(false);
|
const formModel = ref(false);
|
||||||
const formRef = useTemplateRef("form");
|
const formRef = useTemplateRef("form");
|
||||||
|
@ -64,57 +68,40 @@ function addDomain() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const isSubmitting = ref(false);
|
const emit = defineEmits(["submit"]);
|
||||||
|
|
||||||
async function submitNewCertificate() {
|
async function submitNewCertificate() {
|
||||||
if (!formRef.value?.validate()) {
|
if (!formRef.value?.validate()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
isSubmitting.value = true;
|
// Extract country code if country is an object
|
||||||
try {
|
const countryCode = typeof country.value === "object" && country.value !== null
|
||||||
// Extract country code if country is an object
|
? (country.value as Country).alpha2
|
||||||
const countryCode = typeof country.value === "object" && country.value !== null
|
: country.value;
|
||||||
? (country.value as Country).alpha2
|
|
||||||
: country.value;
|
|
||||||
|
|
||||||
// Prepare certificate request data
|
// Prepare certificate request data
|
||||||
const certificateData: Schemas["CertificateInfo"] = {
|
const certificateRequest: Schemas["CertificateInfo"] = {
|
||||||
type: "STANDALONE_CERTIFICATE",
|
type: "STANDALONE_CERTIFICATE",
|
||||||
requestedKeyLength: keyLength.value,
|
requestedKeyLength: keyLength.value,
|
||||||
requestedValidityDays: noExpiry.value ? undefined : validityDays.value,
|
requestedValidityDays: noExpiry.value ? undefined : validityDays.value,
|
||||||
subject: {
|
subject: {
|
||||||
commonName: commonName.value,
|
commonName: commonName.value,
|
||||||
emailAddress: emailAddress.value,
|
emailAddress: emailAddress.value,
|
||||||
organization: organization.value,
|
organization: organization.value,
|
||||||
organizationalUnit: organizationalUnit.value,
|
organizationalUnit: organizationalUnit.value,
|
||||||
country: countryCode,
|
country: countryCode,
|
||||||
state: state.value,
|
state: state.value,
|
||||||
locality: locality.value
|
locality: locality.value
|
||||||
},
|
},
|
||||||
extension: {
|
extension: {
|
||||||
alternativeDnsNames: domains.value
|
alternativeDnsNames: domains.value
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
// Submit certificate request to the backend
|
|
||||||
const response = await fetchClient.POST("/api/certificates", {
|
|
||||||
body: certificateData
|
|
||||||
});
|
|
||||||
|
|
||||||
if (response.error) {
|
|
||||||
console.error("Error submitting certificate:", response.error);
|
|
||||||
// You might want to show an error message to the user here
|
|
||||||
alert("Failed to submit certificate request. Please try again.");
|
|
||||||
} else {
|
|
||||||
console.log("Certificate created successfully:", response.data);
|
|
||||||
// You might want to show a success message or redirect the user
|
|
||||||
alert("Certificate created successfully!");
|
|
||||||
// Reset form or redirect user as needed
|
|
||||||
}
|
}
|
||||||
} finally {
|
};
|
||||||
isSubmitting.value = false;
|
|
||||||
}
|
emit("submit", {
|
||||||
|
certificateRequest
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|
|
@ -1,10 +1,26 @@
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import CertificateEditor from "@/components/CertificateEditor.vue";
|
import CertificateEditor from "@/components/CertificateEditor.vue";
|
||||||
|
import { useMutation } from "@tanstack/vue-query";
|
||||||
|
import { fetchClient } from "@/plugins/client.ts";
|
||||||
|
|
||||||
|
const submitNewCert = useMutation({
|
||||||
|
mutationKey: ["submit-new-certificate"],
|
||||||
|
mutationFn: async (certificate) => {
|
||||||
|
fetchClient.POST("/api/certificates", {
|
||||||
|
body: certificate,
|
||||||
|
})
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
function submitCertificate({ certificate }) {
|
||||||
|
submitNewCert.mutate(certificate);
|
||||||
|
}
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<v-container>
|
<v-container>
|
||||||
<CertificateEditor />
|
<CertificateEditor @submit="submitCertificate" :is-submitting="submitNewCert.isPending" />
|
||||||
</v-container>
|
</v-container>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue