diff --git a/src/main/webapp/app/core/home/home.component.ts b/src/main/webapp/app/core/home/home.component.ts index a7ccd5a..98d9e29 100644 --- a/src/main/webapp/app/core/home/home.component.ts +++ b/src/main/webapp/app/core/home/home.component.ts @@ -9,7 +9,7 @@ export default defineComponent({ const { showLogin } = useLoginModal(); const authenticated = inject>('authenticated'); const username = inject>('currentUsername'); - const utenteAppService = inject('utenteAppService', () => new UtenteAppService()); + const utenteAppService = inject('utenteAppService', () => new UtenteAppService(), true); const profileIncomplete: Ref = ref(false); const checkingProfile: Ref = ref(false); @@ -23,7 +23,7 @@ export default defineComponent({ try { checkingProfile.value = true; const utenteApp = await utenteAppService.getCurrentUser(); - + console.log('utenteApp', utenteApp); // Check if essential profile fields are missing if ( !utenteApp || diff --git a/src/main/webapp/app/entities/prenotazione/prenotazione.component.ts b/src/main/webapp/app/entities/prenotazione/prenotazione.component.ts index 79ddd09..93974a6 100644 --- a/src/main/webapp/app/entities/prenotazione/prenotazione.component.ts +++ b/src/main/webapp/app/entities/prenotazione/prenotazione.component.ts @@ -1,4 +1,4 @@ -import { type Ref, computed, defineComponent, inject, onMounted, ref, watch } from 'vue'; +import { type ComputedRef, type Ref, computed, defineComponent, inject, onMounted, ref, watch } from 'vue'; import { useI18n } from 'vue-i18n'; import { useAlertService } from '@/shared/alert/alert.service'; @@ -12,6 +12,14 @@ import { useAccountStore } from '@/shared/config/store/account-store'; import ConfermaService from '../conferma/conferma.service'; import PrenotazioneService from './prenotazione.service'; +import UtenteAppService from '@/entities/utente-app/utente-app.service'; +import account from '@/router/account.ts'; +import type { IUtenteApp } from '@/shared/model/utente-app.model.ts'; + +import axios from 'axios'; + +const baseApiUrl = 'api/utente-apps'; + export default defineComponent({ name: 'Prenotazione', setup() { @@ -22,6 +30,9 @@ export default defineComponent({ const alertService = inject('alertService', () => useAlertService(), true); const accountStore = useAccountStore(); + const authenticated = inject>('authenticated'); + const utenteAppService = inject('utenteAppService', () => new UtenteAppService(), true); + const itemsPerPage = ref(20); const queryCount: Ref = ref(null); const page: Ref = ref(1); @@ -49,6 +60,57 @@ export default defineComponent({ }); const isSubmittingConferma = ref(false); + // CONTROLLIAMO SE L'UTENTE HA UN PROFILO IMPOSTATO+ + const profileIncomplete: Ref = ref(false); + const checkingProfile: Ref = ref(false); + + const getCurrentUser = async () => { + return new Promise((resolve, reject) => { + axios + .get(`${baseApiUrl}/current`) + .then(res => { + resolve(res.data); + }) + .catch(err => { + reject(err); + }); + }); + }; + + const checkProfileCompletion = async () => { + if (!authenticated.value) { + profileIncomplete.value = false; + return; + } + + try { + checkingProfile.value = true; + const utenteApp = await getCurrentUser(); + // Check if essential profile fields are missing + if ( + !utenteApp || + !utenteApp.nome || + !utenteApp.cognome || + !utenteApp.dataNascita || + !utenteApp.luogoNascita || + !utenteApp.residente || + !utenteApp.telefono + ) { + profileIncomplete.value = true; + } else { + console.log('Profile is complete'); + profileIncomplete.value = false; + } + } catch (error) { + // If UtenteApp doesn't exist, profile is incomplete + profileIncomplete.value = true; + } finally { + checkingProfile.value = false; + } + }; + + // CHIUDIAMO IL CONTROLLO DEL PROFILO IMPOSTATO + const clear = () => { page.value = 1; }; @@ -86,6 +148,7 @@ export default defineComponent({ onMounted(async () => { await retrievePrenotaziones(); + await checkProfileCompletion(); }); const removeId: Ref = ref(null); @@ -162,6 +225,10 @@ export default defineComponent({ await retrievePrenotaziones(); }); + watch(page, async () => { + await checkProfileCompletion(); + }); + return { prenotaziones, handleSyncList, @@ -182,6 +249,10 @@ export default defineComponent({ totalItems, changeOrder, t$, + authenticated, + profileIncomplete, + checkingProfile, + checkProfileCompletion, // Role-based isIncaricato, prenotazioniPendenti, diff --git a/src/main/webapp/app/entities/prenotazione/prenotazione.vue b/src/main/webapp/app/entities/prenotazione/prenotazione.vue index b6b22ee..54d7259 100644 --- a/src/main/webapp/app/entities/prenotazione/prenotazione.vue +++ b/src/main/webapp/app/entities/prenotazione/prenotazione.vue @@ -2,152 +2,160 @@
@@ -211,11 +219,7 @@ {{ t$('entity.action.view') }} - @@ -304,7 +308,11 @@
- +

{{ t$('smartbookingApp.prenotazione.prendiInCarico.subtitle', { id: selectedPrenotazione.id }) }}