fernando-bold commited on
Commit
fa14ef0
·
verified ·
1 Parent(s): f95bdca

'use client'

Browse files

import React, { useState } from 'react'
import { Button } from "@medusajs/ui"
import { useCreateSolarPropertyOwner } from '../../../lib/hooks/solar-property-owners'
import { useCompany } from '../../../lib/hooks/companies'

interface SolarPropertyOwnerRegistrationFormProps {
onSuccess?: () => void
onCancel?: () => void
}

const SolarPropertyOwnerRegistrationForm: React.FC<SolarPropertyOwnerRegistrationFormProps> = ({
onSuccess,
onCancel
}) => {
const [formData, setFormData] = useState({
company_id: '',
property_type: 'RESIDENTIAL_SINGLE_FAMILY',
monthly_consumption: '',
consumption_profile: 'MEDIUM',
roof_area: '',
roof_type: 'FLAT',
roof_orientation: 'SOUTH',
roof_age: 0,
roof_condition: 'good',
shading_issues: 'none',
electrical_capacity: '',
current_energy_rate: '',
preferred_installation_timeline: '3_months',
budget_range: '20k-50k',
financing_interest: 'loan',
property_address: '',
property_city: '',
property_state: '',
property_country: 'Brazil',
utility_company: '',
net_metering_eligible: true,
previous_solar_consideration: false,
solar_installation_year: null as number | null,
energy_goals: [] as string[],
financing_preferences: [] as string[],
installer_preference: [] as string[],
})

const [currentStep, setCurrentStep] = useState(1)
const totalSteps = 3

const { mutateAsync: createPropertyOwner, isPending } = useCreateSolarPropertyOwner()
const { data: companyData } = useCompany({}) // Get company data

const handleInputChange = (
e: React.ChangeEvent<HTMLInputElement | HTMLSelectElement | HTMLTextAreaElement>
) => {
const { name, value, type } = e.target
if (type === 'checkbox') {
const checkbox = e.target as HTMLInputElement
setFormData(prev => ({ ...prev, [name]: checkbox.checked }))
} else {
setFormData(prev => ({ ...prev, [name]: value }))
}
}

const handleArrayChange = (name: string, value: string) => {
setFormData(prev => {
const currentArray = (prev as any)[name] as string[]
const newArray = currentArray.includes(value)
? currentArray.filter(item => item !== value)
: [...currentArray, value]
return { ...prev, [name]: newArray }
})
}

const handleSubmit = async (e: React.FormEvent) => {
e.preventDefault()

try {
// In a real app, you would first create or get the company
// For now, we'll simulate getting a company ID
const company_id = companyData?.companies?.[0]?.id || 'comp_123'

await createPropertyOwner({
...formData,
company_id,
solar_installation_year: formData.solar_installation_year || undefined
})

onSuccess?.()
} catch (error) {
console.error('Error creating solar property owner:', error)
alert('Erro ao registrar proprietário solar. Por favor, tente novamente.')
}
}

// Step 1: Property Information
const renderStep1 = () => (
<div className="space-y-4">
<h3 className="text-lg font-semibold">Informações do Imóvel</h3>

<div className="grid grid-cols-1 md:grid-cols-2 gap-4">
<div>
<label className="text-sm font-medium text-gray-700">Tipo de Propriedade *</label>
<select
name="property_type"
value={formData.property_type}
onChange={handleInputChange}
className="mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-indigo-500 focus:ring-indigo-500 sm:text-sm"
>
<option value="RESIDENTIAL_SINGLE_FAMILY">Residencial Unifamiliar</option>
<option value="RESIDENTIAL_MULTI_FAMILY">Residencial Multifamiliar</option>
<option value="COMMERCIAL_SMALL">Comercial Pequeno</option>
<option value="COMMERCIAL_MEDIUM">Comercial Médio</option>
<option value="COMMERCIAL_LARGE">Comercial Grande</option>
<option value="INDUSTRIAL">Industrial</option>
<option value="AGRICULTURAL">Agrícola</option>
<option value="INSTITUTIONAL">Institucional</option>
</select>
</div>

<div>
<label className="text-sm font-medium text-gray-700">Consumo Mensal (kWh)</label>
<input
type="text"
name="monthly_consumption"
value={formData.monthly_consumption}
onChange={handleInputChange}
placeholder="ex: 400"
className="mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-indigo-500 focus:ring-indigo-500 sm:text-sm"
/>
</div>
</div>

<div className="grid grid-cols-1 md:grid-cols-2 gap-4">
<div>
<label className="text-sm font-medium text-gray-700">Perfil de Consumo</label>
<select
name="consumption_profile"
value={formData.consumption_profile}
onChange={handleInputChange}
className="mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-indigo-500 focus:ring-indigo-500 sm:text-sm"
>
<option value="LOW">Baixo (até 200 kWh/mês)</option>
<option value="MEDIUM">Médio (200-500 kWh/mês)</option>
<option value="HIGH">Alto (500-1000 kWh/mês)</option>
<option value="VERY_HIGH">Muito Alto (mais de 1000 kWh/mês)</option>
</select>
</div>

<div>
<label className="text-sm font-medium text-gray-700">Área do Telhado (m²)</label>
<input
type="text"
name="roof_area"
value={formData.roof_area}
onChange={handleInputChange}
placeholder="ex: 100"
className="mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-indigo-500 focus:ring-indigo-500 sm:text-sm"
/>
</div>
</div>

<div className="grid grid-cols-1 md:grid-cols-3 gap-4">
<div>
<label className="text-sm font-medium text-gray-700">Tipo de Telhado</label>
<select
name="roof_type"
value={formData.roof_type}
onChange={handleInputChange}
className="mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-indigo-500 focus:ring-indigo-500 sm:text-sm"
>
<option value="FLAT">Chapa</option>
<option value="SLOPED_TILE">Inclinado - Telha</option>
<option value="SLOPED_METAL">Inclinado - Metal</option>
<option value="SLOPED_SHINGLE">Inclinado - Shingle</option>
<option value="GABLE">Duas Águas</option>
<option value="HIP">Quatro Águas</option>
</select>
</div>

<div>
<label className="text-sm font-medium text-gray-700">Orientação do Telhado</label>
<select
name="roof_orientation"
value={formData.roof_orientation}
onChange={handleInputChange}
className="mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-indigo-500 focus:ring-indigo-500 sm:text-sm"
>
<option value="NORTH">Norte</option>
<option value="SOUTH">Sul</option>
<option value="EAST">Leste</option>
<option value="WEST">Oeste</option>
<option value="FLAT">Chapa</option>
</select>
</div>

<div>
<label className="text-sm font-medium text-gray-700">Idade do Telhado (anos)</label>
<input
type="number"
name="roof_age"
value={formData.roof_age}
onChange={handleInputChange}
className="mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-indigo-500 focus:ring-indigo-500 sm:text-sm"
/>
</div>
</div>

<div className="grid grid-cols-1 md:grid-cols-2 gap-4">
<div>
<label className="text-sm font-medium text-gray-700">Condição do Telhado</label>
<select
name="roof_condition"
value={formData.roof_condition}
onChange={handleInputChange}
className="mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-indigo-500 focus:ring-indigo-500 sm:text-sm"
>
<option value="good">Boa</option>
<option value="needs_repair">Precisa de Reparos</option>
<option value="poor">Ruim</option>
</select>
</div>

<div>
<label className="text-sm font-medium text-gray-700">Problemas de Sombreamento</label>
<select
name="shading_issues"
value={formData.shading_issues}
onChange={handleInputChange}
className="mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-indigo-500 focus:ring-indigo-500 sm:text-sm"
>
<option value="none">Nenhum</option>
<option value="partial">Parcial</option>
<option value="heavy">Pesado</option>
</select>
</div>
</div>
</div>
)

// Step 2: Energy and Financial Information
const renderStep2 = () => (
<div className="space-y-4">
<h3 className="text-lg font-semibold">Informações Energéticas e Financeiras</h3>

<div className="grid grid-cols-1 md:grid-cols-2 gap-4">
<div>
<label className="text-sm font-medium text-gray-700">Capacidade Elétrica (kW)</label>
<input
type="text"
name="electrical_capacity"
value={formData.electrical_capacity}
onChange={handleInputChange}
placeholder="ex: 25"
className="mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-indigo-500 focus:ring-indigo-500 sm:text-sm"
/>
</div>

<div>
<label className="text-sm font-medium text-gray-700">Tarifa de Energia Atual (R$/kWh)</label>
<input
type="text"
name="current_energy_rate"
value={formData.current_energy_rate}
onChange={handleInputChange}
placeholder="ex: 0.

Files changed (3) hide show
  1. components/navbar.js +2 -1
  2. script.js +11 -2
  3. solar-registration.html +78 -0
components/navbar.js CHANGED
@@ -87,10 +87,11 @@ class CustomNavbar extends HTMLElement {
87
  <div class="nav-links">
88
  <a href="/explore" class="nav-link">Explore</a>
89
  <a href="/dimensions" class="nav-link">Dimensions</a>
 
90
  <a href="/about" class="nav-link">About</a>
91
  <a href="/contact" class="nav-link">Contact</a>
92
  </div>
93
- <button class="mobile-menu-btn">
94
  <i data-feather="menu"></i>
95
  </button>
96
  </nav>
 
87
  <div class="nav-links">
88
  <a href="/explore" class="nav-link">Explore</a>
89
  <a href="/dimensions" class="nav-link">Dimensions</a>
90
+ <a href="/solar-registration.html" class="nav-link">Solar Registration</a>
91
  <a href="/about" class="nav-link">About</a>
92
  <a href="/contact" class="nav-link">Contact</a>
93
  </div>
94
+ <button class="mobile-menu-btn">
95
  <i data-feather="menu"></i>
96
  </button>
97
  </nav>
script.js CHANGED
@@ -7,7 +7,6 @@ document.addEventListener('DOMContentLoaded', () => {
7
  document.documentElement.classList.toggle('dark');
8
  };
9
  });
10
-
11
  // Example component interaction
12
  class VoidExplorer {
13
  constructor() {
@@ -16,7 +15,17 @@ class VoidExplorer {
16
 
17
  init() {
18
  console.log('Void exploration systems online');
 
 
 
 
 
 
 
 
 
 
19
  }
20
  }
21
 
22
- new VoidExplorer();
 
7
  document.documentElement.classList.toggle('dark');
8
  };
9
  });
 
10
  // Example component interaction
11
  class VoidExplorer {
12
  constructor() {
 
15
 
16
  init() {
17
  console.log('Void exploration systems online');
18
+
19
+ // Initialize solar registration form if on that page
20
+ if (window.location.pathname.includes('solar-registration')) {
21
+ this.initSolarRegistration();
22
+ }
23
+ }
24
+
25
+ initSolarRegistration() {
26
+ // This would be replaced with actual form implementation
27
+ console.log('Solar registration system initializing...');
28
  }
29
  }
30
 
31
+ new VoidExplorer();
solar-registration.html ADDED
@@ -0,0 +1,78 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!DOCTYPE html>
2
+ <html lang="en" class="dark">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+ <title>Solar Property Registration | Mystic Void Explorer</title>
7
+ <link rel="stylesheet" href="style.css">
8
+ <script src="https://cdn.tailwindcss.com"></script>
9
+ <script>
10
+ tailwind.config = {
11
+ darkMode: 'class',
12
+ theme: {
13
+ extend: {
14
+ colors: {
15
+ primary: {
16
+ 50: '#f0f9ff',
17
+ 100: '#e0f2fe',
18
+ 200: '#bae6fd',
19
+ 300: '#7dd3fc',
20
+ 400: '#38bdf8',
21
+ 500: '#0ea5e9',
22
+ 600: '#0284c7',
23
+ 700: '#0369a1',
24
+ 800: '#075985',
25
+ 900: '#0c4a6e',
26
+ },
27
+ secondary: {
28
+ 50: '#f5f3ff',
29
+ 100: '#ede9fe',
30
+ 200: '#ddd6fe',
31
+ 300: '#c4b5fd',
32
+ 400: '#a78bfa',
33
+ 500: '#8b5cf6',
34
+ 600: '#7c3aed',
35
+ 700: '#6d28d9',
36
+ 800: '#5b21b6',
37
+ 900: '#4c1d95',
38
+ }
39
+ }
40
+ }
41
+ }
42
+ }
43
+ </script>
44
+ </head>
45
+ <body class="bg-gray-900 text-gray-100 min-h-screen">
46
+ <custom-navbar></custom-navbar>
47
+
48
+ <main class="container mx-auto px-4 py-12 max-w-4xl">
49
+ <div class="bg-gray-800 rounded-xl p-8 shadow-lg">
50
+ <h1 class="text-3xl md:text-4xl font-bold mb-6 text-center bg-clip-text text-transparent bg-gradient-to-r from-primary-400 to-secondary-500">
51
+ Solar Property Registration
52
+ </h1>
53
+
54
+ <div id="solar-registration-form" class="space-y-6">
55
+ <!-- Form steps will be loaded here via JavaScript -->
56
+ </div>
57
+ </div>
58
+ </main>
59
+
60
+ <custom-footer></custom-footer>
61
+
62
+ <script src="components/navbar.js"></script>
63
+ <script src="components/footer.js"></script>
64
+ <script src="script.js"></script>
65
+ <script>
66
+ // This would be replaced with actual form implementation
67
+ document.getElementById('solar-registration-form').innerHTML = `
68
+ <div class="text-center py-12">
69
+ <h3 class="text-xl font-semibold mb-4">Solar Property Registration Coming Soon</h3>
70
+ <p class="text-gray-300">Our solar property registration system is currently under development.</p>
71
+ <a href="/" class="mt-6 inline-block bg-gradient-to-r from-primary-500 to-secondary-600 text-white px-6 py-2 rounded-full font-medium hover:opacity-90 transition-all">
72
+ Return Home
73
+ </a>
74
+ </div>
75
+ `;
76
+ </script>
77
+ </body>
78
+ </html>