useCompanyData.ts 3.0 KB

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