UpgradePremiumButton.vue 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. <template>
  2. <div>
  3. <div :class="['btn_trial', { minimized }]" @click="trialAction()">
  4. <v-icon icon="fa fa-ticket" />
  5. <span v-if="organizationProfile.isTrialActive && !minimized">
  6. <strong>J-{{ organizationProfile.trialCountDown }}</strong>
  7. <br />
  8. </span>
  9. <span v-if="!minimized">{{ btnLabel }}</span>
  10. </div>
  11. <LayoutDialogTrialAlreadyDid
  12. :show="showDialog"
  13. @close-dialog="showDialog = false"
  14. />
  15. </div>
  16. </template>
  17. <script setup lang="ts">
  18. import { computed } from 'vue'
  19. import type { Ref } from 'vue'
  20. import UrlUtils from '~/services/utils/urlUtils'
  21. import { useApiLegacyRequestService } from '~/composables/data/useApiLegacyRequestService'
  22. const runtimeConfig = useRuntimeConfig()
  23. const organizationProfile = useOrganizationProfileStore()
  24. const { apiRequestService } = useApiLegacyRequestService()
  25. const i18n = useI18n()
  26. defineProps({
  27. minimized: {
  28. type: Boolean,
  29. required: false,
  30. default: false,
  31. },
  32. })
  33. const showDialog: Ref<boolean> = ref(false)
  34. const btnLabel = computed(() => {
  35. if (organizationProfile.isTrialActive) {
  36. return i18n.t('trial_started')
  37. }
  38. return organizationProfile.principalType === 'ARTISTIC_PRACTICE_ONLY'
  39. ? i18n.t('try_premium')
  40. : i18n.t('discover_offer')
  41. })
  42. /**
  43. * Lorsque l'on appuie sur le bouton pour démarrer l'essai / découvrir les offres
  44. */
  45. const trialAction = async () => {
  46. const v1BaseURL =
  47. runtimeConfig.baseUrlAdminLegacy || runtimeConfig.public.baseUrlAdminLegacy
  48. if (organizationProfile.isTrialActive) {
  49. await navigateTo(UrlUtils.join(v1BaseURL, '#', 'subscribe'), {
  50. external: true,
  51. })
  52. } else if (organizationProfile.principalType === 'ARTISTIC_PRACTICE_ONLY') {
  53. try {
  54. await apiRequestService.get('/trial/is_available')
  55. await navigateTo(UrlUtils.join(v1BaseURL, '#', 'trial'), {
  56. external: true,
  57. })
  58. } catch (error) {
  59. showDialog.value = true
  60. }
  61. } else {
  62. await navigateTo('/subscription')
  63. }
  64. }
  65. </script>
  66. <style scoped lang="scss">
  67. .btn_trial {
  68. background-color: rgb(var(--v-theme-standout));
  69. border-radius: 5px;
  70. border: 1px solid #fff;
  71. margin-left: 15px;
  72. margin-right: 15px;
  73. text-align: center;
  74. color: #000;
  75. margin-top: 5px;
  76. padding: 5px 10px;
  77. cursor: pointer;
  78. white-space: pre-line;
  79. font-size: 12px;
  80. .v-icon {
  81. font-size: 16px;
  82. color: #000;
  83. padding-right: 5px;
  84. margin: 0 5px 4px 0;
  85. }
  86. }
  87. .minimized {
  88. font-size: 17px;
  89. margin-left: 7px;
  90. margin-right: 7px;
  91. padding: 0;
  92. .v-icon {
  93. padding-right: 0;
  94. margin: 0 0 3px 0;
  95. }
  96. }
  97. </style>