DashboardPage.vue 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  1. <template>
  2. <q-page class="dashboard-page bg-page">
  3. <template v-if="loading">
  4. <div class="row items-center justify-center full-width bg-surface" style="height: 80vh">
  5. <q-spinner-dots color="primary" />
  6. </div>
  7. </template>
  8. <template v-else>
  9. <q-pull-to-refresh color="primary" @refresh="onRefresh">
  10. <DashboardHeaderBar
  11. :data="headerBar"
  12. :notifications="notifications"
  13. />
  14. <DashboardRegistrationIncomplete v-if="!registrationComplete" />
  15. <DashboardSummaryInfos v-else :data="summaryInfos" />
  16. <DashboardPaymentIncomplete v-if="showPaymentBanner" />
  17. <DashboardPendingSchedules
  18. v-if="pendingServicePackages.length > 0"
  19. :data="pendingServicePackages"
  20. :type="'servicePackage'"
  21. progress-class="progress-fill--urgent"
  22. @view-details="openServicePackagePaymentDialog"
  23. />
  24. <DashboardPendingSchedules
  25. v-if="pendingRequests.length > 0"
  26. :data="pendingRequests"
  27. progress-class="progress-fill--loop"
  28. @cancel="openCancelRequestDialog"
  29. />
  30. <DashboardTodaySchedules v-if="todaySchedules.length > 0" :data="todaySchedules" @rate="openRatingDialog" />
  31. <DashboardScrollAreaSchedules />
  32. <DashboardClientProposals v-if="clientProposals.length > 0" :data="clientProposals" @refresh-data="reloadDashboard" />
  33. <DashboardPendingCustomSchedules v-if="customSchedulesNoProposals.length > 0" />
  34. <DashboardNextSchedules v-if="nextSchedules.length > 0" :data="nextSchedules" @view-details="openNextScheduleDialog" />
  35. <DashboardLastDoneSchedules v-if="lastDoneSchedules.length > 0" :data="lastDoneSchedules" />
  36. <DashboardFavoriteProviders v-if="favoriteProviders.length > 0" :data="favoriteProviders" />
  37. <DashboardProvidersClose v-if="providersClose.length > 0" :data="providersClose" />
  38. </q-pull-to-refresh>
  39. </template>
  40. </q-page>
  41. </template>
  42. <script setup>
  43. import DashboardHeaderBar from 'src/components/dashboard/DashboardHeaderBar.vue';
  44. import DashboardSummaryInfos from 'src/components/dashboard/DashboardSummaryInfos.vue';
  45. import DashboardRegistrationIncomplete from 'src/components/dashboard/DashboardRegistrationIncomplete.vue';
  46. import DashboardPaymentIncomplete from 'src/components/dashboard/DashboardPaymentIncomplete.vue';
  47. import DashboardPendingSchedules from 'src/components/dashboard/DashboardPendingSchedules.vue';
  48. import ScheduleAcceptedDialog from 'src/components/dashboard/ScheduleAcceptedDialog.vue';
  49. import ScheduleCancelDialog from 'src/components/dashboard/ScheduleCancelDialog.vue';
  50. import DashboardScrollAreaSchedules from 'src/components/dashboard/DashboardScrollAreaSchedules.vue';
  51. import DashboardNextSchedules from 'src/components/dashboard/DashboardNextSchedules.vue';
  52. import DashboardLastDoneSchedules from 'src/components/dashboard/DashboardLastDoneSchedules.vue';
  53. import DashboardFavoriteProviders from 'src/components/dashboard/DashboardFavoriteProviders.vue';
  54. import DashboardProvidersClose from 'src/components/dashboard/DashboardProvidersClose.vue';
  55. import DashboardTodaySchedules from 'src/components/dashboard/DashboardTodaySchedules.vue';
  56. import FinalSuccesModal from '../schedules/components/FinalSuccesModal.vue';
  57. import DashboardPendingCustomSchedules from 'src/pages/dashboard/components/DashboardPendingCustomSchedules.vue';
  58. import DashboardClientProposals from 'src/pages/dashboard/components/DashboardClientProposals.vue';
  59. import { useRoute, useRouter } from 'vue-router'
  60. import { onMounted, ref, computed } from 'vue';
  61. import { useI18n } from 'vue-i18n';
  62. import { LocalStorage, useQuasar } from 'quasar';
  63. import { dadosDashboard } from 'src/api/dashboard';
  64. import { updateMe } from 'src/api/user';
  65. import { userStore } from 'src/stores/user';
  66. import NextSchedulesDetailsDialog from 'src/components/dashboard/NextSchedulesDetailsDialog.vue';
  67. import ScheduleRatingDialog from 'src/components/dashboard/ScheduleRatingDialog.vue';
  68. const router = useRouter()
  69. const route = useRoute()
  70. const { t } = useI18n();
  71. const $q = useQuasar();
  72. const store = userStore();
  73. const hasPaymentMethods = ref(true);
  74. const headerBar = ref({});
  75. const summaryInfos = ref({});
  76. const pendingSchedules = ref([]);
  77. const pendingServicePackages = ref([]);
  78. const nextSchedules = ref([]);
  79. const clientProposals = ref([]);
  80. const customSchedulesNoProposals = ref([]);
  81. const lastDoneSchedules = ref([]);
  82. const favoriteProviders = ref([]);
  83. const providersClose = ref([]);
  84. const todaySchedules = ref([]);
  85. const notifications = ref([]);
  86. const loading = ref(true);
  87. const registrationComplete = computed(() => store.user?.registration_complete ?? true);
  88. const showPaymentBanner = ref(false);
  89. const successModalKey = ref(
  90. route.query.success ??
  91. (router.currentRoute.value.fullPath.includes('showSuccessModal') ? 'custom_schedule' : null),
  92. );
  93. const successModalContents = {
  94. custom_schedule: null,
  95. order_sent: () => ({
  96. titleLine1: t('service_package.sent_title_line1'),
  97. titleLine2: t('service_package.sent_title_line2'),
  98. subtitleBefore: t('service_package.sent_subtitle_before'),
  99. subtitleHighlight: t('service_package.sent_subtitle_highlight'),
  100. subtitleAfter: t('service_package.sent_subtitle_after'),
  101. }),
  102. };
  103. const pendingRequests = computed(() => {
  104. const seenPackages = new Set();
  105. return pendingSchedules.value.filter((schedule) => {
  106. if (schedule.status !== 'pending') return false;
  107. if (!schedule.service_package_id) return true;
  108. if (seenPackages.has(schedule.service_package_id)) return false;
  109. seenPackages.add(schedule.service_package_id);
  110. return true;
  111. });
  112. });
  113. const openCancelRequestDialog = (schedule) => {
  114. $q.dialog({
  115. component: ScheduleCancelDialog,
  116. componentProps: { schedule },
  117. }).onDismiss(() => {
  118. reloadDashboard(false);
  119. });
  120. };
  121. const openServicePackagePaymentDialog = (servicePackage) => {
  122. $q.dialog({
  123. component: ScheduleAcceptedDialog,
  124. componentProps: { servicePackage }
  125. }).onOk(() => {
  126. reloadDashboard();
  127. });
  128. };
  129. const AUTO_SHOWN_PACKAGES_KEY = "sp_payment_popup_shown_ids";
  130. let autoOpeningPackageDialog = false;
  131. const maybeAutoOpenServicePackagePayment = () => {
  132. if (autoOpeningPackageDialog) return;
  133. const shownIds = LocalStorage.getItem(AUTO_SHOWN_PACKAGES_KEY) ?? [];
  134. const packageToShow = pendingServicePackages.value.find(
  135. (servicePackage) => !shownIds.includes(servicePackage.id),
  136. );
  137. if (!packageToShow) return;
  138. autoOpeningPackageDialog = true;
  139. LocalStorage.set(AUTO_SHOWN_PACKAGES_KEY, [...shownIds, packageToShow.id]);
  140. $q.dialog({
  141. component: ScheduleAcceptedDialog,
  142. componentProps: { servicePackage: packageToShow },
  143. })
  144. .onOk(() => {
  145. reloadDashboard();
  146. })
  147. .onDismiss(() => {
  148. autoOpeningPackageDialog = false;
  149. });
  150. };
  151. const reloadDashboard = async (showLoader = true) => {
  152. if (showLoader) loading.value = true;
  153. const response = await dadosDashboard();
  154. if (response) {
  155. headerBar.value = response.headerBar;
  156. summaryInfos.value = response.summaryInfos;
  157. pendingSchedules.value = response.pendingSchedules ?? [];
  158. pendingServicePackages.value = response.pendingServicePackages ?? [];
  159. nextSchedules.value = response.nextSchedules ?? [];
  160. lastDoneSchedules.value = response.lastDoneSchedules ?? [];
  161. favoriteProviders.value = response.favoriteProviders ?? [];
  162. providersClose.value = response.providersClose ?? [];
  163. clientProposals.value = response.schedulesProposals ?? [];
  164. customSchedulesNoProposals.value = response.customSchedulesNoProposals ?? [];
  165. todaySchedules.value = response.todaySchedules ?? [];
  166. notifications.value = response.notifications ?? [];
  167. hasPaymentMethods.value = response.has_payment_methods ?? true;
  168. }
  169. loading.value = false;
  170. maybeAutoOpenServicePackagePayment();
  171. };
  172. const maybeOpenSuccessModal = () => {
  173. if (!successModalKey.value) return;
  174. if (!(successModalKey.value in successModalContents)) {
  175. successModalKey.value = null;
  176. return;
  177. }
  178. const buildContent = successModalContents[successModalKey.value];
  179. successModalKey.value = null;
  180. $q.dialog({
  181. component: FinalSuccesModal,
  182. componentProps: { content: buildContent ? buildContent() : null },
  183. }).onDismiss(() => {
  184. router.replace({ path: route.path, query: {} });
  185. });
  186. };
  187. const onRefresh = async (done) => {
  188. try {
  189. await reloadDashboard(false);
  190. } finally {
  191. done();
  192. }
  193. };
  194. const openNextScheduleDialog = (schedule) => {
  195. $q.dialog({
  196. component: NextSchedulesDetailsDialog,
  197. componentProps: { schedule }
  198. }).onOk(() => {
  199. reloadDashboard();
  200. });
  201. };
  202. const openRatingDialog = (schedule) => {
  203. $q.dialog({
  204. component: ScheduleRatingDialog,
  205. componentProps: { schedule }
  206. }).onOk(() => {
  207. reloadDashboard()
  208. })
  209. }
  210. onMounted(async () => {
  211. await reloadDashboard();
  212. maybeOpenSuccessModal();
  213. const isFirstAccess = store.user?.client?.first_access ?? false;
  214. showPaymentBanner.value = isFirstAccess && !hasPaymentMethods.value;
  215. if (isFirstAccess) {
  216. updateMe({ first_access: false }).catch(() => {});
  217. store.markFirstAccessSeen();
  218. }
  219. });
  220. </script>
  221. <style scoped>
  222. .dashboard-page {
  223. width: 100%;
  224. min-height: 100%;
  225. box-sizing: border-box;
  226. }
  227. </style>