# All files / js/pages/licenses Edit.vue

0% Statements 0/30
0% Branches 0/76
0% Functions 0/14
0% Lines 0/30

Press n or j to go to the next uncovered block, b, p or k for the previous block.

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238

     <script setup lang="ts">
    import AppLayout from '@/layouts/AppLayout.vue';
    import { Head, Link, useForm } from '@inertiajs/vue3';
    import { computed } from 'vue';
    import { ArrowLeft } from 'lucide-vue-next';
    import licenses from '@/routes/licenses';

    interface Customer {
        id: number;
        name: string;
        email: string | null;
    }

    interface License {
        id: number;
        license_key: string;
        url: string | null;
        customer_id: number;
        limited_users: number;
        standard_users: number;
        status: string;
        notes: string | null;
        expires_at: string | null;
        customer: Customer | null;
    }

    interface Props {
        license: License;
        customers: Customer[];
        canViewFullLicenseKey?: boolean;
    }

    const props = withDefaults(defineProps<Props>(), {
        canViewFullLicenseKey: false,
    });

    const pageTitle = computed(() => {
        if (props.canViewFullLicenseKey) {
            return `Edit License - ${props.license.license_key}`;
        }
        const suffix = props.license.customer?.name ? ` — ${props.license.customer.name}` : '';
        return `Edit License #${props.license.id}${suffix}`;
    });

    const breadcrumbKeyLabel = computed(() => {
        if (props.canViewFullLicenseKey) {
            return props.license.license_key;
        }
        return props.license.customer?.name ?? `License #${props.license.id}`;
    });

    const form = useForm({
        customer_id: props.license.customer_id,
        url: props.license.url || '',
        limited_users: props.license.limited_users,
        standard_users: props.license.standard_users,
        status: props.license.status,
        notes: props.license.notes || '',
        expires_at: props.license.expires_at ? props.license.expires_at.substring(0, 10) : '',
    });

    function submit() {
        form.put(licenses.update(props.license.id).url);
    }
    </script>

    <template>
        <Head :title="pageTitle" />
        <AppLayout :breadcrumbs="[
            { title: 'Licenses', href: licenses.index().url },
            { title: breadcrumbKeyLabel, href: licenses.show(props.license.id).url },
            { title: 'Edit', href: '#' }
        ]">
            <div class="p-6">
                <div class="mb-6">
                    <Link
                        :href="licenses.show(props.license.id).url"
                        class="mb-4 inline-flex items-center gap-2 text-sm text-gray-600 hover:text-gray-900"
                    >
                        <ArrowLeft class="h-4 w-4" />
                        Back to License
                    </Link>
                    <h1 class="text-2xl font-bold text-gray-900">Edit License</h1>
                    <p class="mt-1 font-mono text-sm text-gray-500">{{ props.license.license_key }}</p>
                    <p v-if="!canViewFullLicenseKey" class="mt-1 text-sm text-gray-500">
                        Full license keys are visible only to administrators.
                    </p>
                </div>

                <div class="rounded-lg border border-gray-200 bg-white p-6">
                    <form @submit.prevent="submit" class="space-y-6">
                        <!-- Customer Selection -->
                        <div>
                            <h2 class="mb-4 text-lg font-semibold text-gray-900">Customer</h2>
                            <div>
                                <label class="mb-1 block text-sm font-medium text-gray-700">
                                    Select Customer <span class="text-red-500">*</span>
                                </label>
                                <select
                                    v-model="form.customer_id"
                                    required
                                    class="w-full rounded border px-3 py-2 focus:border-blue-500 focus:ring-2 focus:ring-blue-500"
                                    :class="{ 'border-red-500': form.errors.customer_id }"
                                >
                                    <option value="">— Select a customer —</option>
                                    <option v-for="customer in props.customers" :key="customer.id" :value="customer.id">
                                        {{ customer.name }}{{ customer.email ? ` (${customer.email})` : '' }}
                                    </option>
                                </select>
                                <div v-if="form.errors.customer_id" class="mt-1 text-sm text-red-600">
                                    {{ form.errors.customer_id }}
                                </div>
                            </div>
                        </div>

                        <!-- Instance URL -->
                        <div>
                            <h2 class="mb-4 text-lg font-semibold text-gray-900">Instance URL</h2>
                            <div>
                                <label class="mb-1 block text-sm font-medium text-gray-700">
                                    Authorized URL
                                </label>
                                <input
                                    v-model="form.url"
                                    type="url"
                                    placeholder="https://customer-instance.example.com"
                                    class="w-full rounded border px-3 py-2 focus:border-blue-500 focus:ring-2 focus:ring-blue-500"
                                    :class="{ 'border-red-500': form.errors.url }"
                                />
                                <p class="mt-1 text-xs text-gray-500">The URL of the instance authorized to use this license. Validation requests must originate from this URL.</p>
                                <div v-if="form.errors.url" class="mt-1 text-sm text-red-600">
                                    {{ form.errors.url }}
                                </div>
                            </div>
                        </div>

                        <!-- User Limits -->
                        <div>
                            <h2 class="mb-4 text-lg font-semibold text-gray-900">User Limits</h2>
                            <div class="grid gap-6 md:grid-cols-2">
                                <div>
                                    <label class="mb-1 block text-sm font-medium text-gray-700">
                                        Limited Users <span class="text-red-500">*</span>
                                    </label>
                                    <input
                                        v-model.number="form.limited_users"
                                        type="number"
                                        min="0"
                                        required
                                        class="w-full rounded border px-3 py-2 focus:border-blue-500 focus:ring-2 focus:ring-blue-500"
                                        :class="{ 'border-red-500': form.errors.limited_users }"
                                    />
                                    <div v-if="form.errors.limited_users" class="mt-1 text-sm text-red-600">
                                        {{ form.errors.limited_users }}
                                    </div>
                                </div>

                                <div>
                                    <label class="mb-1 block text-sm font-medium text-gray-700">
                                        Standard Users <span class="text-red-500">*</span>
                                    </label>
                                    <input
                                        v-model.number="form.standard_users"
                                        type="number"
                                        min="0"
                                        required
                                        class="w-full rounded border px-3 py-2 focus:border-blue-500 focus:ring-2 focus:ring-blue-500"
                                        :class="{ 'border-red-500': form.errors.standard_users }"
                                    />
                                    <div v-if="form.errors.standard_users" class="mt-1 text-sm text-red-600">
                                        {{ form.errors.standard_users }}
                                    </div>
                                </div>
                            </div>
                        </div>

                        <!-- License Settings -->
                        <div>
                            <h2 class="mb-4 text-lg font-semibold text-gray-900">License Settings</h2>
                            <div class="grid gap-6 md:grid-cols-2">
                                <div>
                                    <label class="mb-1 block text-sm font-medium text-gray-700">Status</label>
                                    <select
                                        v-model="form.status"
                                        class="w-full rounded border px-3 py-2 focus:border-blue-500 focus:ring-2 focus:ring-blue-500"
                                    >
                                        <option value="active">Active</option>
                                        <option value="suspended">Suspended</option>
                                        <option value="expired">Expired</option>
                                        <option value="revoked">Revoked</option>
                                    </select>
                                </div>

                                <div>
                                    <label class="mb-1 block text-sm font-medium text-gray-700">Expiry Date</label>
                                    <input
                                        v-model="form.expires_at"
                                        type="date"
                                        class="w-full rounded border px-3 py-2 focus:border-blue-500 focus:ring-2 focus:ring-blue-500"
                                    />
                                    <p class="mt-1 text-xs text-gray-500">Leave blank for no expiry.</p>
                                </div>
                            </div>
                        </div>

                        <!-- Notes -->
                        <div>
                            <label class="mb-1 block text-sm font-medium text-gray-700">Notes</label>
                            <textarea
                                v-model="form.notes"
                                rows="3"
                                class="w-full rounded border px-3 py-2 focus:border-blue-500 focus:ring-2 focus:ring-blue-500"
                                placeholder="Optional notes about this license..."
                            ></textarea>
                        </div>

                        <!-- Actions -->
                        <div class="flex items-center justify-end gap-3 border-t pt-6">
                            <Link
                                :href="licenses.show(props.license.id).url"
                                class="rounded-md border border-gray-300 bg-white px-4 py-2 text-sm font-medium text-gray-700 hover:bg-gray-50"
                            >
                                Cancel
                            </Link>
                            <button
                                type="submit"
                                :disabled="form.processing"
                                class="rounded-md bg-blue-600 px-4 py-2 text-sm font-medium text-white hover:bg-blue-700 disabled:opacity-50"
                            >
                                {{ form.processing ? 'Saving...' : 'Save Changes' }}
                            </button>
                        </div>
                    </form>
                </div>
            </div>
        </AppLayout>
    </template>