UpgradePremiumButton.vue 2.5 KB

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