You've already forked isop-mirror
Merge branch 'feature/80-Odstránenie-účtu-používateľa-garantom-' into develop
This commit is contained in:
@@ -13,6 +13,13 @@ const companyId = route.params.id;
|
||||
const loading = ref(true);
|
||||
const saving = ref(false);
|
||||
|
||||
// Delete state
|
||||
const deleteDialog = ref(false);
|
||||
const deleteLoading = ref(false);
|
||||
const deleteError = ref<string | null>(null);
|
||||
const deleteSuccess = ref(false);
|
||||
const company = ref<CompanyData | null>(null);
|
||||
|
||||
const form = ref({
|
||||
name: '',
|
||||
address: '',
|
||||
@@ -31,6 +38,7 @@ const { data } = await useSanctumFetch<CompanyData>(`/api/companies/${companyId}
|
||||
|
||||
watch(data, (newData) => {
|
||||
if (newData) {
|
||||
company.value = newData;
|
||||
form.value.name = newData.name;
|
||||
form.value.address = newData.address;
|
||||
form.value.ico = newData.ico;
|
||||
@@ -67,6 +75,49 @@ async function saveChanges() {
|
||||
function cancel() {
|
||||
navigateTo('/dashboard/admin/companies');
|
||||
}
|
||||
|
||||
// Funkcia na otvorenie delete dialogu
|
||||
const openDeleteDialog = () => {
|
||||
deleteDialog.value = true;
|
||||
deleteError.value = null;
|
||||
};
|
||||
|
||||
// Funkcia na zatvorenie dialogu
|
||||
const closeDeleteDialog = () => {
|
||||
deleteDialog.value = false;
|
||||
deleteError.value = null;
|
||||
deleteSuccess.value = false;
|
||||
};
|
||||
|
||||
// Funkcia na vymazanie firmy
|
||||
const deleteCompany = async () => {
|
||||
if (!companyId) return;
|
||||
|
||||
deleteLoading.value = true;
|
||||
deleteError.value = null;
|
||||
|
||||
try {
|
||||
await client(`/api/companies/${companyId}`, {
|
||||
method: 'DELETE'
|
||||
});
|
||||
|
||||
deleteSuccess.value = true;
|
||||
|
||||
// Presmeruj na zoznam po 1.5 sekundách
|
||||
setTimeout(() => {
|
||||
navigateTo('/dashboard/admin/companies');
|
||||
}, 1500);
|
||||
|
||||
} catch (e) {
|
||||
if (e instanceof FetchError) {
|
||||
deleteError.value = e.response?._data?.message || 'Chyba pri mazaní firmy.';
|
||||
} else {
|
||||
deleteError.value = 'Neznáma chyba pri mazaní firmy.';
|
||||
}
|
||||
} finally {
|
||||
deleteLoading.value = false;
|
||||
}
|
||||
};
|
||||
</script>
|
||||
|
||||
<template>
|
||||
@@ -125,11 +176,53 @@ function cancel() {
|
||||
<v-btn @click="cancel" :disabled="saving">
|
||||
Zrušiť
|
||||
</v-btn>
|
||||
<v-spacer></v-spacer>
|
||||
<v-btn color="red" variant="outlined" @click="openDeleteDialog" :disabled="saving">
|
||||
Vymazať firmu
|
||||
</v-btn>
|
||||
</v-card-actions>
|
||||
</v-card>
|
||||
</v-col>
|
||||
</v-row>
|
||||
</div>
|
||||
|
||||
<!-- Delete Confirmation Dialog -->
|
||||
<v-dialog v-model="deleteDialog" max-width="500px">
|
||||
<v-card>
|
||||
<v-card-title class="text-h5">
|
||||
Potvrdiť vymazanie
|
||||
</v-card-title>
|
||||
<v-card-text>
|
||||
<p v-if="!deleteSuccess">
|
||||
Naozaj chcete vymazať firmu <strong>{{ company?.name }}</strong>?
|
||||
</p>
|
||||
<p v-if="!deleteSuccess" class="text-error mt-2">
|
||||
Táto akcia vymaže aj kontaktnú osobu (EMPLOYER), všetky praxe a statusy spojené s touto firmou a
|
||||
<strong>nie je možné ju vrátiť späť</strong>.
|
||||
</p>
|
||||
|
||||
<!-- Error message -->
|
||||
<v-alert v-if="deleteError" type="error" density="compact" class="mt-3">
|
||||
{{ deleteError }}
|
||||
</v-alert>
|
||||
|
||||
<!-- Success message -->
|
||||
<v-alert v-if="deleteSuccess" type="success" density="compact" class="mt-3">
|
||||
Firma bola úspešne vymazaná. Presmerovanie...
|
||||
</v-alert>
|
||||
</v-card-text>
|
||||
<v-card-actions>
|
||||
<v-spacer></v-spacer>
|
||||
<v-btn color="grey" variant="text" @click="closeDeleteDialog" :disabled="deleteLoading">
|
||||
Zrušiť
|
||||
</v-btn>
|
||||
<v-btn color="red" variant="text" @click="deleteCompany" :loading="deleteLoading"
|
||||
:disabled="deleteSuccess">
|
||||
Vymazať
|
||||
</v-btn>
|
||||
</v-card-actions>
|
||||
</v-card>
|
||||
</v-dialog>
|
||||
</v-container>
|
||||
</template>
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
<script setup lang="ts">
|
||||
import type { CompanyData } from '~/types/company_data';
|
||||
import { FetchError } from 'ofetch';
|
||||
|
||||
definePageMeta({
|
||||
middleware: ['sanctum:auth', 'admin-only'],
|
||||
@@ -22,7 +23,54 @@ const headers = [
|
||||
{ title: 'Operácie', key: 'ops', align: 'middle' },
|
||||
];
|
||||
|
||||
const { data, error } = await useSanctumFetch<CompanyData[]>('/api/companies/simple');
|
||||
const client = useSanctumClient();
|
||||
|
||||
const { data, error, refresh } = await useSanctumFetch<CompanyData[]>('/api/companies/simple');
|
||||
|
||||
// State pre delete dialog
|
||||
const deleteDialog = ref(false);
|
||||
const companyToDelete = ref<CompanyData | null>(null);
|
||||
const deleteLoading = ref(false);
|
||||
const deleteError = ref<string | null>(null);
|
||||
|
||||
// Funkcia na otvorenie delete dialogu
|
||||
const openDeleteDialog = (company: CompanyData) => {
|
||||
companyToDelete.value = company;
|
||||
deleteDialog.value = true;
|
||||
deleteError.value = null;
|
||||
};
|
||||
|
||||
// Funkcia na zatvorenie dialogu
|
||||
const closeDeleteDialog = () => {
|
||||
deleteDialog.value = false;
|
||||
companyToDelete.value = null;
|
||||
deleteError.value = null;
|
||||
};
|
||||
|
||||
// Funkcia na vymazanie firmy
|
||||
const deleteCompany = async () => {
|
||||
if (!companyToDelete.value) return;
|
||||
|
||||
deleteLoading.value = true;
|
||||
deleteError.value = null;
|
||||
|
||||
try {
|
||||
await client(`/api/companies/${companyToDelete.value.id}`, {
|
||||
method: 'DELETE'
|
||||
});
|
||||
|
||||
refresh();
|
||||
closeDeleteDialog();
|
||||
|
||||
} catch (err) {
|
||||
if (err instanceof FetchError) {
|
||||
deleteError.value = err.data?.message;
|
||||
}
|
||||
} finally {
|
||||
deleteLoading.value = false;
|
||||
}
|
||||
};
|
||||
|
||||
</script>
|
||||
|
||||
<template>
|
||||
@@ -62,14 +110,46 @@ const { data, error } = await useSanctumFetch<CompanyData[]>('/api/companies/sim
|
||||
<td class="text-left">
|
||||
<v-btn class="m-1 op-btn" density="compact" append-icon="mdi-pencil" base-color="orange"
|
||||
:to="'/dashboard/admin/companies/edit/' + item.id">Editovať</v-btn>
|
||||
<v-btn class="m-1 op-btn" density="compact" append-icon="mdi-trash-can-outline"
|
||||
base-color="red" @click="async () => { }">Zmazať</v-btn>
|
||||
<v-btn class="m-1 op-btn" density="compact" append-icon="mdi-delete" base-color="red"
|
||||
@click="openDeleteDialog(item)">Vymazať</v-btn>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</v-table>
|
||||
</div>
|
||||
</v-card>
|
||||
|
||||
<!-- Delete Confirmation Dialog -->
|
||||
<v-dialog v-model="deleteDialog" max-width="500px">
|
||||
<v-card>
|
||||
<v-card-title class="text-h5">
|
||||
Potvrdiť vymazanie
|
||||
</v-card-title>
|
||||
<v-card-text>
|
||||
<p>
|
||||
Naozaj chcete vymazať firmu <strong>{{ companyToDelete?.name }}</strong>?
|
||||
</p>
|
||||
<p class="text-error mt-2">
|
||||
Táto akcia vymaže aj kontaktnú osobu (EMPLOYER), všetky praxe a statusy spojené s touto firmou a
|
||||
<strong>nie je možné ju vrátiť späť</strong>.
|
||||
</p>
|
||||
|
||||
<!-- Error message -->
|
||||
<v-alert v-if="deleteError" type="error" density="compact" class="mt-3">
|
||||
{{ deleteError }}
|
||||
</v-alert>
|
||||
</v-card-text>
|
||||
<v-card-actions>
|
||||
<v-spacer></v-spacer>
|
||||
<v-btn color="grey" variant="text" @click="closeDeleteDialog" :disabled="deleteLoading">
|
||||
Zrušiť
|
||||
</v-btn>
|
||||
<v-btn color="red" variant="text" @click="deleteCompany" :loading="deleteLoading">
|
||||
Vymazať
|
||||
</v-btn>
|
||||
</v-card-actions>
|
||||
</v-card>
|
||||
</v-dialog>
|
||||
</v-container>
|
||||
</template>
|
||||
|
||||
|
||||
@@ -14,6 +14,12 @@ const student = ref<User | null>(null);
|
||||
const loading = ref(true);
|
||||
const saving = ref(false);
|
||||
|
||||
// Delete state
|
||||
const deleteDialog = ref(false);
|
||||
const deleteLoading = ref(false);
|
||||
const deleteError = ref<string | null>(null);
|
||||
const deleteSuccess = ref(false);
|
||||
|
||||
const form = ref({
|
||||
first_name: '',
|
||||
last_name: '',
|
||||
@@ -69,6 +75,49 @@ async function saveChanges() {
|
||||
function cancel() {
|
||||
navigateTo('/dashboard/admin/students');
|
||||
}
|
||||
|
||||
// Funkcia na otvorenie delete dialogu
|
||||
const openDeleteDialog = () => {
|
||||
deleteDialog.value = true;
|
||||
deleteError.value = null;
|
||||
};
|
||||
|
||||
// Funkcia na zatvorenie dialogu
|
||||
const closeDeleteDialog = () => {
|
||||
deleteDialog.value = false;
|
||||
deleteError.value = null;
|
||||
deleteSuccess.value = false;
|
||||
};
|
||||
|
||||
// Funkcia na vymazanie študenta
|
||||
const deleteStudent = async () => {
|
||||
if (!studentId) return;
|
||||
|
||||
deleteLoading.value = true;
|
||||
deleteError.value = null;
|
||||
|
||||
try {
|
||||
await client(`/api/students/${studentId}`, {
|
||||
method: 'DELETE'
|
||||
});
|
||||
|
||||
deleteSuccess.value = true;
|
||||
|
||||
// Presmeruj na zoznam po 1.5 sekundách
|
||||
setTimeout(() => {
|
||||
navigateTo('/dashboard/admin/students');
|
||||
}, 1500);
|
||||
|
||||
} catch (e) {
|
||||
if (e instanceof FetchError) {
|
||||
deleteError.value = e.response?._data?.message || 'Chyba pri mazaní študenta.';
|
||||
} else {
|
||||
deleteError.value = 'Neznáma chyba pri mazaní študenta.';
|
||||
}
|
||||
} finally {
|
||||
deleteLoading.value = false;
|
||||
}
|
||||
};
|
||||
</script>
|
||||
|
||||
<template>
|
||||
@@ -124,11 +173,53 @@ function cancel() {
|
||||
<v-btn @click="cancel" :disabled="saving">
|
||||
Zrušiť
|
||||
</v-btn>
|
||||
<v-spacer></v-spacer>
|
||||
<v-btn color="red" variant="outlined" @click="openDeleteDialog" :disabled="saving">
|
||||
Vymazať študenta
|
||||
</v-btn>
|
||||
</v-card-actions>
|
||||
</v-card>
|
||||
</v-col>
|
||||
</v-row>
|
||||
</div>
|
||||
|
||||
<!-- Delete Confirmation Dialog -->
|
||||
<v-dialog v-model="deleteDialog" max-width="500px">
|
||||
<v-card>
|
||||
<v-card-title class="text-h5">
|
||||
Potvrdiť vymazanie
|
||||
</v-card-title>
|
||||
<v-card-text>
|
||||
<p v-if="!deleteSuccess">
|
||||
Naozaj chcete vymazať študenta <strong>{{ student?.name }}</strong>?
|
||||
</p>
|
||||
<p v-if="!deleteSuccess" class="text-error mt-2">
|
||||
Táto akcia vymaže aj všetky súvisiace dáta (praxe, statusy, atď.) a <strong>nie je možné ju
|
||||
vrátiť späť</strong>.
|
||||
</p>
|
||||
|
||||
<!-- Error message -->
|
||||
<v-alert v-if="deleteError" type="error" density="compact" class="mt-3">
|
||||
{{ deleteError }}
|
||||
</v-alert>
|
||||
|
||||
<!-- Success message -->
|
||||
<v-alert v-if="deleteSuccess" type="success" density="compact" class="mt-3">
|
||||
Študent bol úspešne vymazaný. Presmerovanie...
|
||||
</v-alert>
|
||||
</v-card-text>
|
||||
<v-card-actions>
|
||||
<v-spacer></v-spacer>
|
||||
<v-btn color="grey" variant="text" @click="closeDeleteDialog" :disabled="deleteLoading">
|
||||
Zrušiť
|
||||
</v-btn>
|
||||
<v-btn color="red" variant="text" @click="deleteStudent" :loading="deleteLoading"
|
||||
:disabled="deleteSuccess">
|
||||
Vymazať
|
||||
</v-btn>
|
||||
</v-card-actions>
|
||||
</v-card>
|
||||
</v-dialog>
|
||||
</v-container>
|
||||
</template>
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
<script setup lang="ts">
|
||||
import type { User } from '~/types/user';
|
||||
import { FetchError } from 'ofetch';
|
||||
|
||||
definePageMeta({
|
||||
middleware: ['sanctum:auth', 'admin-only'],
|
||||
@@ -22,8 +23,54 @@ const headers = [
|
||||
{ title: 'Operácie', key: 'ops', align: 'middle' },
|
||||
];
|
||||
|
||||
const client = useSanctumClient();
|
||||
|
||||
// Načítame všetkých študentov
|
||||
const { data: students, error } = await useSanctumFetch<User[]>('/api/students');
|
||||
const { data: students, error, refresh } = await useSanctumFetch<User[]>('/api/students');
|
||||
|
||||
// State pre delete dialog
|
||||
const deleteDialog = ref(false);
|
||||
const studentToDelete = ref<User | null>(null);
|
||||
const deleteLoading = ref(false);
|
||||
const deleteError = ref<string | null>(null);
|
||||
|
||||
// Funkcia na otvorenie delete dialogu
|
||||
const openDeleteDialog = (student: User) => {
|
||||
studentToDelete.value = student;
|
||||
deleteDialog.value = true;
|
||||
deleteError.value = null;
|
||||
};
|
||||
|
||||
// Funkcia na zatvorenie dialogu
|
||||
const closeDeleteDialog = () => {
|
||||
deleteDialog.value = false;
|
||||
studentToDelete.value = null;
|
||||
deleteError.value = null;
|
||||
};
|
||||
|
||||
// Funkcia na vymazanie študenta
|
||||
const deleteStudent = async () => {
|
||||
if (!studentToDelete.value) return;
|
||||
|
||||
deleteLoading.value = true;
|
||||
deleteError.value = null;
|
||||
|
||||
try {
|
||||
await client(`/api/students/${studentToDelete.value.id}`, {
|
||||
method: 'DELETE'
|
||||
});
|
||||
|
||||
refresh();
|
||||
closeDeleteDialog();
|
||||
|
||||
} catch (err) {
|
||||
if (err instanceof FetchError) {
|
||||
deleteError.value = err.data?.message;
|
||||
}
|
||||
} finally {
|
||||
deleteLoading.value = false;
|
||||
}
|
||||
};
|
||||
</script>
|
||||
|
||||
<template>
|
||||
@@ -63,6 +110,8 @@ const { data: students, error } = await useSanctumFetch<User[]>('/api/students')
|
||||
<td class="text-left">
|
||||
<v-btn class="m-1 op-btn" density="compact" append-icon="mdi-pencil" base-color="orange"
|
||||
:to="'/dashboard/admin/students/edit/' + item.id">Editovať</v-btn>
|
||||
<v-btn class="m-1 op-btn" density="compact" append-icon="mdi-delete" base-color="red"
|
||||
@click="openDeleteDialog(item)">Vymazať</v-btn>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
@@ -72,6 +121,38 @@ const { data: students, error } = await useSanctumFetch<User[]>('/api/students')
|
||||
class="mt-4"></v-alert>
|
||||
</div>
|
||||
</v-card>
|
||||
|
||||
<!-- Delete Confirmation Dialog -->
|
||||
<v-dialog v-model="deleteDialog" max-width="500px">
|
||||
<v-card>
|
||||
<v-card-title class="text-h5">
|
||||
Potvrdiť vymazanie
|
||||
</v-card-title>
|
||||
<v-card-text>
|
||||
<p>
|
||||
Naozaj chcete vymazať študenta <strong>{{ studentToDelete?.name }}</strong>?
|
||||
</p>
|
||||
<p class="text-error mt-2">
|
||||
Táto akcia vymaže aj všetky súvisiace dáta (praxe, statusy, atď.) a <strong>nie je možné ju
|
||||
vrátiť späť</strong>.
|
||||
</p>
|
||||
|
||||
<!-- Error message -->
|
||||
<v-alert v-if="deleteError" type="error" density="compact" class="mt-3">
|
||||
{{ deleteError }}
|
||||
</v-alert>
|
||||
</v-card-text>
|
||||
<v-card-actions>
|
||||
<v-spacer></v-spacer>
|
||||
<v-btn color="grey" variant="text" @click="closeDeleteDialog" :disabled="deleteLoading">
|
||||
Zrušiť
|
||||
</v-btn>
|
||||
<v-btn color="red" variant="text" @click="deleteStudent" :loading="deleteLoading">
|
||||
Vymazať
|
||||
</v-btn>
|
||||
</v-card-actions>
|
||||
</v-card>
|
||||
</v-dialog>
|
||||
</v-container>
|
||||
</template>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user