Files
OpenVPN-Monitoring-Simple/APP_UI/src/components/NewClientModal.vue
T
ayurishchevandClaude Sonnet 5.5 897c82ab88 UI review, stage 3: cleanup, shared chart code, confirmations, routing
useTrafficChart composable replaces the duplicated chart code in Analytics
and HistoryModal; theme observer is released on unmount; blob URLs are
revoked. ConfirmModal gets a unique id; confirm() in Server/PKI and
SweetAlert2 in Account are replaced by ConfirmModal and toasts, sweetalert2
and sass removed. Separate authApiClient for /api/auth. 404 redirect, lazy
Clients, token-based isAuthenticated, theme from prefers-color-scheme set
before mount. BaseModal reactive size, NewClientModal name check and focus
on opened, HistoryModal ignores stale answers. Login.vue.bak, the dead
global axios interceptor and empty <p> removed.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-07 13:10:41 +03:00

60 lines
2.1 KiB
Vue

<template>
<BaseModal id="newClientModal" title="Create New Client" ref="modal" @opened="inputRef?.focus()">
<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.
</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">
Create Client
</button>
</template>
</BaseModal>
</template>
<script setup>
import { ref, computed } from 'vue';
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));
const open = () => {
clientName.value = '';
modal.value.show(); // the input is focused on the opened event
};
const close = () => {
modal.value.hide();
};
const confirm = () => {
if (isValid.value) {
emit('create', clientName.value);
close();
}
};
defineExpose({ open, close });
</script>