useCompanyData.ts 2.8 KB

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