Files
OpenVPN-Monitoring-Simple/APP_UI/src/components/NewClientModal.vue
T

59 lines
2.1 KiB
Vue
Raw Normal View History

2026-01-28 22:37:47 +03:00
<template>
<BaseModal id="newClientModal" title="Create New Client" ref="modal" @opened="inputRef?.focus()">
2026-01-28 22:37:47 +03:00
<template #body>
<div class="mb-3">
<label for="clientName" class="form-label small text-muted text-uppercase fw-bold">Client Name</label>
<div class="input-group">
<span class="input-group-text"><i class="fas fa-user"></i></span>
<input type="text" class="form-control" :class="{ 'is-invalid': clientName && !isValid }" id="clientName"
v-model="clientName" placeholder="e.g. laptop-user" maxlength="64" autocomplete="off" @keyup.enter="confirm" ref="inputRef">
</div>
<div v-if="clientName && !isValid" class="text-danger small mt-2">
Letters, digits, dashes and underscores only; the first character must be a letter or a digit.
2026-01-28 22:37:47 +03:00
</div>
<div class="form-text mt-2 text-muted small">
<i class="fas fa-info-circle me-1"></i> Use only alphanumeric characters, dashes, or underscores.
</div>
</div>
</template>
<template #footer>
<button type="button" class="btn-action btn-action-secondary" @click="close">Cancel</button>
<button type="button" class="btn-action btn-action-save" @click="confirm" :disabled="!isValid">
2026-01-28 22:37:47 +03:00
Create Client
</button>
</template>
</BaseModal>
</template>
<script setup>
import { ref, computed } from 'vue';
2026-01-28 22:37:47 +03:00
import BaseModal from './BaseModal.vue';
const emit = defineEmits(['create']);
const modal = ref(null);
const clientName = ref('');
const inputRef = ref(null);
// Same rule as the profiler API (without dots): 1-64 characters, no leading dash or underscore
const NAME_RE = /^[A-Za-z0-9][A-Za-z0-9_-]{0,63}$/;
const isValid = computed(() => NAME_RE.test(clientName.value));
2026-01-28 22:37:47 +03:00
const open = () => {
clientName.value = '';
modal.value.show(); // the input is focused on the opened event
2026-01-28 22:37:47 +03:00
};
const close = () => {
modal.value.hide();
};
const confirm = () => {
if (isValid.value) {
2026-01-28 22:37:47 +03:00
emit('create', clientName.value);
close();
}
};
defineExpose({ open, close });
</script>