# All files / js/pages/company-settings Index.vue

0% Statements 0/32
0% Branches 0/54
0% Functions 0/21
0% Lines 0/32

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

     <script setup lang="ts">
    import ListTableActionLabel from '@/components/ListTableActionLabel.vue';
    import AppLayout from '@/layouts/AppLayout.vue';
    import { Head, Link, router } from '@inertiajs/vue3';
    import companySettings from '@/routes/company-settings';
    import { Plus, Edit, Trash2, Building2, Star } from 'lucide-vue-next';
    import { getSafeExternalUrl } from '@/composables/useSafeExternalUrl';

    interface Company {
        id: number;
        name: string;
        email: string;
        phone: string;
        address: string;
        city: string;
        state: string;
        postal_code: string;
        country: string;
        website: string;
        logo_path: string;
        description: string;
        is_active: boolean;
        is_default: boolean;
        created_at: string;
        updated_at: string;
    }

    interface Props {
        companies: Company[];
        currentCompany: Company;
    }

    const props = defineProps<Props>();

    function deleteCompany(company: Company) {
        if (confirm(`Are you sure you want to delete "${company.name}"?`)) {
            router.delete(companySettings.destroy(company.id).url);
        }
    }

    function setAsDefault(company: Company) {
        router.post(companySettings.setDefault(company.id).url);
    }

    function switchToCompany(company: Company) {
        router.post(companySettings.switch(company.id).url);
    }

    function safeCompanyWebsite(website: string) {
        return getSafeExternalUrl(website);
    }
    </script>

    <template>
        <Head title="Company Settings" />

        <AppLayout :breadcrumbs="[
            { title: 'Administration', href: '/administration' },
            { title: 'Company Settings', href: '#' }
        ]">
            <div class="p-4">
                <!-- Header -->
                <div class="mb-6 flex items-center justify-between">
                    <div>
                        <h1 class="text-2xl font-bold text-gray-900">Company Settings</h1>
                        <p class="text-gray-600">Manage your companies and organization information</p>
                        <div v-if="props.currentCompany" class="mt-2">
                            <span class="text-sm text-gray-500">Current Company: </span>
                            <span class="text-sm font-medium text-blue-600">{{ props.currentCompany.name }}</span>
                        </div>
                        <div v-else class="mt-2">
                            <span class="text-sm text-red-600">No accessible companies found</span>
                        </div>
                    </div>
                    <Link
                        :href="companySettings.create().url"
                        class="flex items-center gap-2 rounded-md bg-blue-600 px-4 py-2 text-white hover:bg-blue-700"
                    >
                        <Plus class="h-4 w-4" />
                        Add Company
                    </Link>
                </div>

                <!-- Companies List -->
                <div v-if="props.companies.length === 0" class="rounded-lg border bg-white p-8 text-center">
                    <Building2 class="mx-auto h-12 w-12 text-gray-400" />
                    <h3 class="mt-2 text-lg font-medium text-gray-900">No accessible companies</h3>
                    <p class="mt-1 text-gray-500">You don't have access to any companies or no companies are active.</p>
                    <p class="mt-2 text-sm text-gray-400">Contact an administrator to get access to companies.</p>
                    <div class="mt-6">
                        <Link
                            :href="companySettings.create().url"
                            class="inline-flex items-center gap-2 rounded-md bg-blue-600 px-4 py-2 text-white hover:bg-blue-700"
                        >
                            <Plus class="h-4 w-4" />
                            Add Company
                        </Link>
                    </div>
                </div>

                <div v-else class="grid gap-6 md:grid-cols-2 lg:grid-cols-3">
                    <div
                        v-for="company in props.companies"
                        :key="company.id"
                        class="cursor-pointer rounded-lg border bg-white p-6 shadow-sm transition-shadow hover:shadow-md focus:outline-none focus:ring-2 focus:ring-inset focus:ring-blue-500"
                        tabindex="0"
                        role="link"
                        @click="router.visit(companySettings.show(company.id).url)"
                        @keydown.enter.prevent="router.visit(companySettings.show(company.id).url)"
                        @keydown.space.prevent="router.visit(companySettings.show(company.id).url)"
                    >
                        <!-- Company Header -->
                        <div class="mb-4 flex items-start justify-between">
                            <div class="flex items-center gap-3">
                                <div class="flex h-12 w-12 items-center justify-center rounded-lg bg-blue-100">
                                    <Building2 class="h-6 w-6 text-blue-600" />
                                </div>
                                <div>
                                    <div class="flex items-center gap-2">
                                        <h3 class="font-semibold text-gray-900">{{ company.name }}</h3>
                                        <Star v-if="company.is_default" class="h-4 w-4 text-yellow-500 fill-current" />
                                    </div>
                                    <p class="text-sm text-gray-500">{{ company.city }}, {{ company.country }}</p>
                                </div>
                            </div>
                            <span
                                :class="[
                                    'rounded-full px-2 py-1 text-xs font-medium',
                                    company.is_active ? 'bg-green-100 text-green-800' : 'bg-red-100 text-red-800'
                                ]"
                            >
                                {{ company.is_active ? 'Active' : 'Inactive' }}
                            </span>
                        </div>

                        <!-- Company Details -->
                        <div class="mb-4 space-y-2 text-sm text-gray-600">
                            <div v-if="company.email" class="flex items-center gap-2">
                                <span class="font-medium">Email:</span>
                                <span>{{ company.email }}</span>
                            </div>
                            <div v-if="company.phone" class="flex items-center gap-2">
                                <span class="font-medium">Phone:</span>
                                <span>{{ company.phone }}</span>
                            </div>
                            <div v-if="safeCompanyWebsite(company.website)" class="flex items-center gap-2">
                                <span class="font-medium">Website:</span>
                                <a :href="safeCompanyWebsite(company.website) || '#'" target="_blank" rel="noopener noreferrer" class="text-blue-600 hover:underline" @click.stop>
                                    {{ safeCompanyWebsite(company.website) }}
                                </a>
                            </div>
                        </div>

                        <!-- Description -->
                        <p v-if="company.description" class="mb-4 text-sm text-gray-600 line-clamp-2">
                            {{ company.description }}
                        </p>

                        <!-- Actions -->
                        <div class="flex items-center gap-2" @click.stop>
                            <button
                                v-if="props.currentCompany && props.currentCompany.id !== company.id"
                                type="button"
                                @click="switchToCompany(company)"
                                class="inline-flex items-center justify-center rounded border border-blue-300 px-2 py-1.5 text-sm text-blue-700 hover:bg-blue-50 md:px-3 md:py-1"
                            >
                                <ListTableActionLabel label="Switch to">
                                    <Building2 class="h-4 w-4" />
                                </ListTableActionLabel>
                            </button>
                            <Link
                                :href="companySettings.edit(company.id).url"
                                class="inline-flex items-center justify-center rounded border px-2 py-1.5 text-sm text-gray-700 hover:bg-gray-50 md:px-3 md:py-1"
                            >
                                <ListTableActionLabel label="Edit">
                                    <Edit class="h-4 w-4" />
                                </ListTableActionLabel>
                            </Link>
                            <button
                                v-if="!company.is_default"
                                type="button"
                                @click="setAsDefault(company)"
                                class="inline-flex items-center justify-center rounded border border-yellow-300 px-2 py-1.5 text-sm text-yellow-700 hover:bg-yellow-50 md:px-3 md:py-1"
                            >
                                <ListTableActionLabel label="Set default">
                                    <Star class="h-4 w-4" />
                                </ListTableActionLabel>
                            </button>
                            <button
                                type="button"
                                @click="deleteCompany(company)"
                                class="inline-flex items-center justify-center rounded border border-red-300 px-2 py-1.5 text-sm text-red-700 hover:bg-red-50 md:px-3 md:py-1"
                            >
                                <ListTableActionLabel label="Delete">
                                    <Trash2 class="h-4 w-4" />
                                </ListTableActionLabel>
                            </button>
                        </div>
                    </div>
                </div>
            </div>
        </AppLayout>
    </template>