blob: 3a8cd3f0a87593573ff1a26ee414ca0aa50b479b [file] [log] [blame]
Yoshie Muranaka37393812020-03-24 15:25:24 -07001<template>
2 <b-modal id="upload-certificate" ref="modal" @ok="onOk" @hidden="resetForm">
Derick Montague602e98a2020-10-21 16:20:00 -05003 <template #modal-title>
Yoshie Muranaka37393812020-03-24 15:25:24 -07004 <template v-if="certificate">
Sandeepa Singhb4406162021-07-26 15:05:39 +05305 {{ $t('pageCertificates.replaceCertificate') }}
Yoshie Muranaka37393812020-03-24 15:25:24 -07006 </template>
7 <template v-else>
Sandeepa Singhb4406162021-07-26 15:05:39 +05308 {{ $t('pageCertificates.addNewCertificate') }}
Yoshie Muranaka37393812020-03-24 15:25:24 -07009 </template>
10 </template>
11 <b-form>
12 <!-- Replace Certificate type -->
13 <template v-if="certificate !== null">
14 <dl class="mb-4">
Sandeepa Singhb4406162021-07-26 15:05:39 +053015 <dt>{{ $t('pageCertificates.modal.certificateType') }}</dt>
Yoshie Muranaka37393812020-03-24 15:25:24 -070016 <dd>{{ certificate.certificate }}</dd>
17 </dl>
18 </template>
19
20 <!-- Add new Certificate type -->
21 <template v-else>
22 <b-form-group
Sandeepa Singhb4406162021-07-26 15:05:39 +053023 :label="$t('pageCertificates.modal.certificateType')"
Yoshie Muranaka37393812020-03-24 15:25:24 -070024 label-for="certificate-type"
25 >
26 <b-form-select
27 id="certificate-type"
28 v-model="form.certificateType"
29 :options="certificateOptions"
Surya Vde23ea22024-07-11 15:19:46 +053030 :state="getValidationState(v$.form.certificateType)"
31 @input="v$.form.certificateType.$touch()"
Yoshie Muranaka37393812020-03-24 15:25:24 -070032 >
33 </b-form-select>
34 <b-form-invalid-feedback role="alert">
Surya Vde23ea22024-07-11 15:19:46 +053035 <template v-if="!v$.form.certificateType.required">
Yoshie Muranaka37393812020-03-24 15:25:24 -070036 {{ $t('global.form.fieldRequired') }}
37 </template>
38 </b-form-invalid-feedback>
39 </b-form-group>
40 </template>
41
Sandeepa Singhb4406162021-07-26 15:05:39 +053042 <b-form-group :label="$t('pageCertificates.modal.certificateFile')">
SurenNeware978807d2020-09-03 18:35:21 +053043 <form-file
Yoshie Muranaka37393812020-03-24 15:25:24 -070044 id="certificate-file"
45 v-model="form.file"
46 accept=".pem"
Surya Vde23ea22024-07-11 15:19:46 +053047 :state="getValidationState(v$.form.file)"
SurenNeware978807d2020-09-03 18:35:21 +053048 >
49 <template #invalid>
50 <b-form-invalid-feedback role="alert">
51 {{ $t('global.form.required') }}
52 </b-form-invalid-feedback>
Yoshie Muranaka37393812020-03-24 15:25:24 -070053 </template>
SurenNeware978807d2020-09-03 18:35:21 +053054 </form-file>
Yoshie Muranaka37393812020-03-24 15:25:24 -070055 </b-form-group>
56 </b-form>
Derick Montague602e98a2020-10-21 16:20:00 -050057 <template #modal-ok>
Yoshie Muranaka37393812020-03-24 15:25:24 -070058 <template v-if="certificate">
59 {{ $t('global.action.replace') }}
60 </template>
61 <template v-else>
62 {{ $t('global.action.add') }}
63 </template>
64 </template>
Sukanya Pandey38357132020-12-22 13:40:59 +053065 <template #modal-cancel>
66 {{ $t('global.action.cancel') }}
67 </template>
Yoshie Muranaka37393812020-03-24 15:25:24 -070068 </b-modal>
69</template>
70
71<script>
Ed Tanous7d6b44c2024-03-23 14:56:34 -070072import { required, requiredIf } from '@vuelidate/validators';
SurenNeware61859092020-10-01 09:37:32 +053073import VuelidateMixin from '@/components/Mixins/VuelidateMixin.js';
Ed Tanous7d6b44c2024-03-23 14:56:34 -070074import { useVuelidate } from '@vuelidate/core';
Yoshie Muranaka37393812020-03-24 15:25:24 -070075
SurenNeware978807d2020-09-03 18:35:21 +053076import FormFile from '@/components/Global/FormFile';
Surya Vde23ea22024-07-11 15:19:46 +053077import { useI18n } from 'vue-i18n';
SurenNeware978807d2020-09-03 18:35:21 +053078
Yoshie Muranaka37393812020-03-24 15:25:24 -070079export default {
SurenNeware978807d2020-09-03 18:35:21 +053080 components: { FormFile },
Yoshie Muranaka37393812020-03-24 15:25:24 -070081 mixins: [VuelidateMixin],
82 props: {
83 certificate: {
84 type: Object,
85 default: null,
Derick Montague602e98a2020-10-21 16:20:00 -050086 validator: (prop) => {
Yoshie Muranaka37393812020-03-24 15:25:24 -070087 if (prop === null) return true;
88 return (
Yoshie Muranakaefd7c882020-10-30 09:32:06 -070089 Object.prototype.hasOwnProperty.call(prop, 'type') &&
90 Object.prototype.hasOwnProperty.call(prop, 'certificate')
Yoshie Muranaka37393812020-03-24 15:25:24 -070091 );
Derick Montague602e98a2020-10-21 16:20:00 -050092 },
93 },
Yoshie Muranaka37393812020-03-24 15:25:24 -070094 },
Ed Tanous7d6b44c2024-03-23 14:56:34 -070095 setup() {
96 return {
97 v$: useVuelidate(),
98 };
99 },
Yoshie Muranaka37393812020-03-24 15:25:24 -0700100 data() {
101 return {
Surya Vde23ea22024-07-11 15:19:46 +0530102 $t: useI18n().t,
Yoshie Muranaka37393812020-03-24 15:25:24 -0700103 form: {
104 certificateType: null,
Derick Montague602e98a2020-10-21 16:20:00 -0500105 file: null,
106 },
Yoshie Muranaka37393812020-03-24 15:25:24 -0700107 };
108 },
109 computed: {
110 certificateTypes() {
Sandeepa Singhb4406162021-07-26 15:05:39 +0530111 return this.$store.getters['certificates/availableUploadTypes'];
Yoshie Muranaka37393812020-03-24 15:25:24 -0700112 },
113 certificateOptions() {
114 return this.certificateTypes.map(({ type, label }) => {
115 return {
116 text: label,
Derick Montague602e98a2020-10-21 16:20:00 -0500117 value: type,
Yoshie Muranaka37393812020-03-24 15:25:24 -0700118 };
119 });
Derick Montague602e98a2020-10-21 16:20:00 -0500120 },
Yoshie Muranaka37393812020-03-24 15:25:24 -0700121 },
122 watch: {
Derick Montague602e98a2020-10-21 16:20:00 -0500123 certificateOptions: function (options) {
Yoshie Muranaka37393812020-03-24 15:25:24 -0700124 if (options.length) {
125 this.form.certificateType = options[0].value;
126 }
Derick Montague602e98a2020-10-21 16:20:00 -0500127 },
Yoshie Muranaka37393812020-03-24 15:25:24 -0700128 },
129 validations() {
130 return {
131 form: {
132 certificateType: {
Derick Montague602e98a2020-10-21 16:20:00 -0500133 required: requiredIf(function () {
Yoshie Muranaka37393812020-03-24 15:25:24 -0700134 return !this.certificate;
Derick Montague602e98a2020-10-21 16:20:00 -0500135 }),
Yoshie Muranaka37393812020-03-24 15:25:24 -0700136 },
137 file: {
Derick Montague602e98a2020-10-21 16:20:00 -0500138 required,
139 },
140 },
Yoshie Muranaka37393812020-03-24 15:25:24 -0700141 };
142 },
143 methods: {
144 handleSubmit() {
Surya Vde23ea22024-07-11 15:19:46 +0530145 this.v$.$touch();
146 if (this.v$.$invalid) return;
Yoshie Muranaka37393812020-03-24 15:25:24 -0700147 this.$emit('ok', {
148 addNew: !this.certificate,
149 file: this.form.file,
150 location: this.certificate ? this.certificate.location : null,
151 type: this.certificate
152 ? this.certificate.type
Derick Montague602e98a2020-10-21 16:20:00 -0500153 : this.form.certificateType,
Yoshie Muranaka37393812020-03-24 15:25:24 -0700154 });
155 this.closeModal();
156 },
157 closeModal() {
158 this.$nextTick(() => {
159 this.$refs.modal.hide();
160 });
161 },
162 resetForm() {
163 this.form.certificateType = this.certificateOptions.length
164 ? this.certificateOptions[0].value
165 : null;
166 this.form.file = null;
Surya Vde23ea22024-07-11 15:19:46 +0530167 this.v$.$reset();
Yoshie Muranaka37393812020-03-24 15:25:24 -0700168 },
169 onOk(bvModalEvt) {
170 // prevent modal close
171 bvModalEvt.preventDefault();
172 this.handleSubmit();
Derick Montague602e98a2020-10-21 16:20:00 -0500173 },
174 },
Yoshie Muranaka37393812020-03-24 15:25:24 -0700175};
176</script>