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

'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 (2) hide show
  1. script.js +179 -2
  2. solar-registration.html +45 -3
script.js CHANGED
@@ -21,10 +21,187 @@ class VoidExplorer {
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
 
 
21
  this.initSolarRegistration();
22
  }
23
  }
 
24
  initSolarRegistration() {
 
25
  console.log('Solar registration system initializing...');
26
+
27
+ // Form state
28
+ const formData = {
29
+ company_id: '',
30
+ property_type: 'RESIDENTIAL_SINGLE_FAMILY',
31
+ monthly_consumption: '',
32
+ consumption_profile: 'MEDIUM',
33
+ roof_area: '',
34
+ roof_type: 'FLAT',
35
+ roof_orientation: 'SOUTH',
36
+ roof_age: 0,
37
+ roof_condition: 'good',
38
+ shading_issues: 'none',
39
+ electrical_capacity: '',
40
+ current_energy_rate: '',
41
+ preferred_installation_timeline: '3_months',
42
+ budget_range: '20k-50k',
43
+ financing_interest: 'loan',
44
+ property_address: '',
45
+ property_city: '',
46
+ property_state: '',
47
+ property_country: 'Brazil',
48
+ utility_company: '',
49
+ net_metering_eligible: true,
50
+ previous_solar_consideration: false,
51
+ solar_installation_year: null,
52
+ energy_goals: [],
53
+ financing_preferences: [],
54
+ installer_preference: [],
55
+ };
56
+
57
+ let currentStep = 1;
58
+ const totalSteps = 3;
59
+
60
+ // DOM elements
61
+ const form = document.getElementById('registration-form');
62
+ const stepCounter = document.getElementById('step-counter');
63
+ const progressBar = document.getElementById('progress-bar');
64
+ const nextButton = document.getElementById('next-button');
65
+ const submitButton = document.getElementById('submit-button');
66
+ const backButtonContainer = document.getElementById('back-button-container');
67
+
68
+ // Step containers
69
+ const step1 = document.getElementById('step-1');
70
+ const step2 = document.getElementById('step-2');
71
+ const step3 = document.getElementById('step-3');
72
+
73
+ // Render step 1
74
+ step1.innerHTML = `
75
+ <h3 class="text-lg font-semibold">Informações do Imóvel</h3>
76
+
77
+ <div class="grid grid-cols-1 md:grid-cols-2 gap-4">
78
+ <div>
79
+ <label class="text-sm font-medium text-gray-700">Tipo de Propriedade *</label>
80
+ <select name="property_type" class="mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-indigo-500 focus:ring-indigo-500 sm:text-sm">
81
+ <option value="RESIDENTIAL_SINGLE_FAMILY">Residencial Unifamiliar</option>
82
+ <option value="RESIDENTIAL_MULTI_FAMILY">Residencial Multifamiliar</option>
83
+ <option value="COMMERCIAL_SMALL">Comercial Pequeno</option>
84
+ <option value="COMMERCIAL_MEDIUM">Comercial Médio</option>
85
+ <option value="COMMERCIAL_LARGE">Comercial Grande</option>
86
+ <option value="INDUSTRIAL">Industrial</option>
87
+ <option value="AGRICULTURAL">Agrícola</option>
88
+ <option value="INSTITUTIONAL">Institucional</option>
89
+ </select>
90
+ </div>
91
+
92
+ <div>
93
+ <label class="text-sm font-medium text-gray-700">Consumo Mensal (kWh)</label>
94
+ <input type="text" name="monthly_consumption" placeholder="ex: 400" class="mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-indigo-500 focus:ring-indigo-500 sm:text-sm">
95
+ </div>
96
+ </div>
97
+
98
+ <!-- Additional step 1 fields would be added here -->
99
+ `;
100
+
101
+ // Render step 2
102
+ step2.innerHTML = `
103
+ <h3 class="text-lg font-semibold">Informações Energéticas e Financeiras</h3>
104
+
105
+ <div class="grid grid-cols-1 md:grid-cols-2 gap-4">
106
+ <div>
107
+ <label class="text-sm font-medium text-gray-700">Capacidade Elétrica (kW)</label>
108
+ <input type="text" name="electrical_capacity" placeholder="ex: 25" class="mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-indigo-500 focus:ring-indigo-500 sm:text-sm">
109
+ </div>
110
+
111
+ <div>
112
+ <label class="text-sm font-medium text-gray-700">Tarifa de Energia Atual (R$/kWh)</label>
113
+ <input type="text" name="current_energy_rate" placeholder="ex: 0.85" class="mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-indigo-500 focus:ring-indigo-500 sm:text-sm">
114
+ </div>
115
+ </div>
116
+
117
+ <!-- Additional step 2 fields would be added here -->
118
+ `;
119
+
120
+ // Render step 3
121
+ step3.innerHTML = `
122
+ <h3 class="text-lg font-semibold">Objetivos e Preferências</h3>
123
+
124
+ <div>
125
+ <label class="text-sm font-medium text-gray-700">Objetivos de Energia</label>
126
+ <div class="mt-1 space-y-2">
127
+ <div class="flex items-center">
128
+ <input id="goal-reduce_cost" name="energy_goals" type="checkbox" value="reduce_cost" class="h-4 w-4 rounded border-gray-300 text-indigo-600 focus:ring-indigo-500">
129
+ <label for="goal-reduce_cost" class="ml-2 block text-sm text-gray-900">Reduzir custos</label>
130
+ </div>
131
+ <!-- Additional checkboxes would be added here -->
132
+ </div>
133
+ </div>
134
+
135
+ <!-- Additional step 3 fields would be added here -->
136
+ `;
137
+
138
+ // Event listeners
139
+ nextButton.addEventListener('click', () => {
140
+ currentStep++;
141
+ updateForm();
142
+ });
143
+
144
+ form.addEventListener('submit', (e) => {
145
+ e.preventDefault();
146
+ // Collect all form data
147
+ const formElements = form.elements;
148
+ for (let i = 0; i < formElements.length; i++) {
149
+ const element = formElements[i];
150
+ if (element.name) {
151
+ if (element.type === 'checkbox') {
152
+ if (element.checked) {
153
+ if (!formData[element.name]) {
154
+ formData[element.name] = [];
155
+ }
156
+ formData[element.name].push(element.value);
157
+ }
158
+ } else {
159
+ formData[element.name] = element.value;
160
+ }
161
+ }
162
+ }
163
+
164
+ console.log('Form submitted:', formData);
165
+ alert('Cadastro enviado com sucesso!');
166
+ // In a real app, you would send this data to your backend
167
+ });
168
+
169
+ function updateForm() {
170
+ // Update step counter
171
+ stepCounter.textContent = `Passo ${currentStep} de ${totalSteps}`;
172
+
173
+ // Update progress bar
174
+ progressBar.style.width = `${(currentStep / totalSteps) * 100}%`;
175
+
176
+ // Show/hide steps
177
+ step1.classList.toggle('hidden', currentStep !== 1);
178
+ step2.classList.toggle('hidden', currentStep !== 2);
179
+ step3.classList.toggle('hidden', currentStep !== 3);
180
+
181
+ // Update buttons
182
+ if (currentStep === totalSteps) {
183
+ nextButton.classList.add('hidden');
184
+ submitButton.classList.remove('hidden');
185
+ } else {
186
+ nextButton.classList.remove('hidden');
187
+ submitButton.classList.add('hidden');
188
+ }
189
+
190
+ // Update back button
191
+ if (currentStep > 1) {
192
+ backButtonContainer.innerHTML = `
193
+ <button id="back-button" type="button" class="bg-gray-500 text-white px-6 py-2 rounded-full font-medium hover:opacity-90 transition-all">
194
+ Voltar
195
+ </button>
196
+ `;
197
+ document.getElementById('back-button').addEventListener('click', () => {
198
+ currentStep--;
199
+ updateForm();
200
+ });
201
+ } else {
202
+ backButtonContainer.innerHTML = '';
203
+ }
204
+ }
205
  }
206
  }
207
 
solar-registration.html CHANGED
@@ -50,11 +50,53 @@
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>
 
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
  <div id="solar-registration-form" class="space-y-6">
54
+ <form id="registration-form" class="space-y-6">
55
+ <div class="mb-6">
56
+ <div class="flex items-center justify-between mb-4">
57
+ <h2 class="text-xl font-bold">Registro de Proprietário Solar</h2>
58
+ <div id="step-counter" class="text-sm text-gray-500">
59
+ Passo 1 de 3
60
+ </div>
61
+ </div>
62
+
63
+ <div class="w-full bg-gray-200 rounded-full h-2.5">
64
+ <div id="progress-bar"
65
+ class="bg-blue-600 h-2.5 rounded-full transition-all duration-300"
66
+ style="width: 33.33%"
67
+ ></div>
68
+ </div>
69
+ </div>
70
+
71
+ <div id="step-1" class="space-y-4">
72
+ <!-- Step 1 content will be inserted here by JavaScript -->
73
+ </div>
74
+
75
+ <div id="step-2" class="space-y-4 hidden">
76
+ <!-- Step 2 content will be inserted here by JavaScript -->
77
+ </div>
78
+
79
+ <div id="step-3" class="space-y-4 hidden">
80
+ <!-- Step 3 content will be inserted here by JavaScript -->
81
+ </div>
82
+
83
+ <div class="flex justify-between pt-4">
84
+ <div id="back-button-container">
85
+ <!-- Back button will be inserted here when needed -->
86
+ </div>
87
+
88
+ <div class="flex space-x-3">
89
+ <button id="next-button" type="button" class="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">
90
+ Próximo
91
+ </button>
92
+ <button id="submit-button" type="submit" class="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 hidden">
93
+ Cadastrar
94
+ </button>
95
+ </div>
96
+ </div>
97
+ </form>
98
  </div>
99
+ </div>
100
  </main>
101
 
102
  <custom-footer></custom-footer>