useCompanyData.ts 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. interface CompanySettings {
  2. hero_background_url: string | null
  3. hero_title: string | null
  4. hero_subtitle: string | null
  5. stat1_value: string | null
  6. stat1_label: string | null
  7. stat1_icon: string | null
  8. stat2_value: string | null
  9. stat2_label: string | null
  10. stat2_icon: string | null
  11. stat3_value: string | null
  12. stat3_label: string | null
  13. stat3_icon: string | null
  14. about_vision: string | null
  15. about_mission: string | null
  16. about_values: string | null
  17. about_history: string | null
  18. contact_email: string | null
  19. contact_phone: string | null
  20. contact_location: string | null
  21. }
  22. interface CompanyBenefit {
  23. id: number
  24. title: string
  25. icon: string
  26. description: string | null
  27. order: number
  28. }
  29. interface ApiResponse<T> {
  30. payload: T
  31. }
  32. const FALLBACK_SETTINGS: CompanySettings = {
  33. hero_background_url: null,
  34. hero_title: 'Serprati é fazer parte de algo maior',
  35. hero_subtitle: 'Benefícios exclusivos, parceiros de qualidade e uma comunidade que cuida de você e sua família.',
  36. stat1_value: '1.000+',
  37. stat1_label: 'Associados',
  38. stat1_icon: 'mdi-account-group',
  39. stat2_value: '50+',
  40. stat2_label: 'Parceiros',
  41. stat2_icon: 'mdi-handshake',
  42. stat3_value: '30+',
  43. stat3_label: 'Anos de História',
  44. stat3_icon: 'mdi-heart-outline',
  45. about_vision: null,
  46. about_mission: null,
  47. about_values: null,
  48. about_history: null,
  49. contact_email: 'serprati@serprati.com.br',
  50. contact_phone: '45 99126-6531',
  51. contact_location: 'Toledo - PR',
  52. }
  53. const FALLBACK_BENEFITS: CompanyBenefit[] = [
  54. { id: 1, title: 'Descontos Exclusivos', icon: 'mdi-tag', description: 'Até 50% de desconto em parceiros selecionados.', order: 1 },
  55. { id: 2, title: 'Convênios Médicos', icon: 'mdi-hospital-box-outline', description: 'Planos de saúde com condições especiais.', order: 2 },
  56. { id: 3, title: 'Loja do Associado', icon: 'mdi-store-outline', description: 'Produtos com preços diferenciados.', order: 3 },
  57. { id: 4, title: 'Carteirinha Digital', icon: 'mdi-card-account-details-outline', description: 'Acesso rápido aos benefícios pelo celular.', order: 4 },
  58. { id: 5, title: 'Notificações', icon: 'mdi-bell-outline', description: 'Fique por dentro das novidades e promoções.', order: 5 },
  59. { id: 6, title: 'Dependentes', icon: 'mdi-human-male-female-child', description: 'Inclua sua família nos benefícios.', order: 6 },
  60. ]
  61. export const useCompanyData = () => {
  62. const { apiUrl } = useRuntimeConfig().public
  63. const { data: settingsData } = useAsyncData('company-settings', () =>
  64. $fetch<ApiResponse<CompanySettings>>(`${apiUrl}/api/company-settings`).catch(() => null),
  65. )
  66. const { data: benefitsData } = useAsyncData('company-benefits', () =>
  67. $fetch<ApiResponse<CompanyBenefit[]>>(`${apiUrl}/api/company-benefits`).catch(() => null),
  68. )
  69. const settings = computed<CompanySettings>(() => {
  70. const payload = settingsData.value?.payload
  71. if (!payload) return FALLBACK_SETTINGS
  72. return { ...FALLBACK_SETTINGS, ...payload }
  73. })
  74. const benefits = computed<CompanyBenefit[]>(() => {
  75. const payload = benefitsData.value?.payload
  76. if (!Array.isArray(payload) || payload.length === 0) return FALLBACK_BENEFITS
  77. return payload
  78. })
  79. return { settings, benefits }
  80. }