Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 58 additions & 14 deletions src/containers/NewContractMember/pages/NewContractMemberSummary.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ import Button from '@mui/material/Button'

import { useTheme } from '@mui/material/styles'
import Typography from '@mui/material/Typography'
import Stack from '@mui/material/Stack'
import Grid from '@mui/material/Grid'
import Box from '@mui/material/Box'
import Divider from '@mui/material/Divider'

import FormControlLabel from '@mui/material/FormControlLabel'
Expand Down Expand Up @@ -53,6 +55,9 @@ const NewContractMemberSummary = (props) => {

const [loading, setLoading] = useState(false)
const [prices, setPrices] = useState({})

const [estimatedMonthlykWh, setEstimatedMonthlykWh] = useState(null)
const [estimatedMonthlyTotalEur, setEstimatedMonthlyTotalEur] = useState(null)
const [openGeneralTermsDialog, setOpenGeneralTermsDialog] = useState(false)
const [showReviewLinks, setShowReviewLinks] = useState(false)

Expand Down Expand Up @@ -403,18 +408,28 @@ const NewContractMemberSummary = (props) => {
)

const cityId = values?.supply_point_address?.city?.id || null
const powers = powerFields.map(
(power) => String(Math.round(Number(power) * THOUSANDS_CONVERSION_FACTOR))
)

getPrices({
tariff:
values.contract.power_type === 'power-higher-15kw' ? '3.0TD' : '2.0TD',
max_power: maxPower,
vat: values.new_member?.nif ? values.new_member.nif : values.member.nif,
cnae: values.supply_point.cnae,
city_id: cityId
city_id: cityId,
powers: powers,
pricelist_type: isTariffIndexed ? 'index' : 'periods'
})
.then((response) => {
const tariffPrices = response?.data['current']
const estimatedMonthlykWh = response?.data['estimated_monthly_kwh']
const estimatedMonthlyTotalEur = response?.data['estimated_monthly_total_eur']

setPrices(tariffPrices)
setEstimatedMonthlykWh(estimatedMonthlykWh)
setEstimatedMonthlyTotalEur(estimatedMonthlyTotalEur)
setLoading(false)
})
.catch((error) => {
Expand All @@ -424,9 +439,11 @@ const NewContractMemberSummary = (props) => {
}, [
values.contract.power,
values.contract.power_type,
values.new_member.nif,
values.new_member?.nif,
values.member?.nif,
values.supply_point.cnae,
values?.supply_point_address?.city?.id
values?.supply_point_address?.city?.id,
isTariffIndexed
])

const handleCheckboxChange = async (event, fieldName) => {
Expand Down Expand Up @@ -500,21 +517,48 @@ const NewContractMemberSummary = (props) => {
</Grid>
</Grid>
)}
{estimatedMonthlykWh && (
<>
<Grid item xs={12}>
<Divider sx={{ my: 2 }} />
</Grid>
<Grid item xs={12}>
<Stack spacing={2} sx={{
color: 'secondary.dark'
}}>
<Typography variant="body.xs.regular">
{t('SIMULATION_PRICES_TITLE')}
</Typography>
<Box
sx={theme.typography['body.xs.regular']}
dangerouslySetInnerHTML={{
__html: t('SIMULATION_PRICES_BODY', {
estimated_monthly_kwh: estimatedMonthlykWh,
estimated_monthly_total_eur: estimatedMonthlyTotalEur,
})
}}>
</Box>
</Stack>
</Grid>
</>)}
<Grid item xs={12}>
<Divider sx={{ my: 2 }} />
</Grid>
<Grid item xs={12}>
<Typography variant="body2">
{t('SUMMARY_OTHER_CONCEPTS_TITLE')}
</Typography>
</Grid>
<Grid item xs={12}>
<Typography
variant="body2"
dangerouslySetInnerHTML={{
__html: t('SUMMARY_OTHER_CONCEPTS_BODY')
}}
/>
<Stack spacing={2} sx={{
color: 'secondary.dark'
}}>
<Typography variant="body.xs.regular">
{t('SUMMARY_OTHER_CONCEPTS_TITLE')}
</Typography>
<Box
component="ul"
sx={theme.typography['body.xs.regular']}
dangerouslySetInnerHTML={{
__html: t('SUMMARY_OTHER_CONCEPTS_BODY')
}}>
</Box>
</Stack>
</Grid>
<Grid item xs={12}>
<Divider sx={{ my: 2 }} />
Expand Down
4 changes: 3 additions & 1 deletion src/i18n/locale-ca.json
Original file line number Diff line number Diff line change
Expand Up @@ -860,5 +860,7 @@
"PRICES_ERROR_MISSING_DATA": "No hi ha dades disponibles per a aquesta data. Disculpa les molèsties!",
"API_ERROR_FETCHING_DATA": "Malauradament, no podem mostrar ara la previsió de preus, a causa d’una incidència. Esperem que es pugui resoldre de seguida i poder mostrar-la al més aviat possible. Disculpa les molèsties!",
"15YEARS_CAMPAIGN": "Celebrem 15 anys!",
"15YEARS_DESCRIPTION": "De 100 a 0 €: contracta la llum sense associar-te"
"15YEARS_DESCRIPTION": "De 100 a 0 €: contracta la llum sense associar-te",
"SIMULATION_PRICES_TITLE": "Preu estimat",
"SIMULATION_PRICES_BODY": "El consum mitjà d'un contracte amb la teva potència és de {{ estimated_monthly_kwh }} kWh. Tenint en compte la tarifa escollida, el preu mitjà del mes passat i els impostos vigents, el cost estimat seria de {{ estimated_monthly_total_eur }} €. Aquest import és una estimació orientativa de la teva facturació mensual i pot variar segons la compensació d'excedents, perfils de consum i altres variables. No reflecteix l'import real final de la teva factura a Som Energia. Per a una comparativa més ajustada al teu consum final, escriu a <a target=\"_blank\" href=\"mailto:hola@somenergia.coop\">hola@somenergia.coop</a> i t'ajudarem encantades."
}
4 changes: 3 additions & 1 deletion src/i18n/locale-es.json
Original file line number Diff line number Diff line change
Expand Up @@ -860,5 +860,7 @@
"PRICES_ERROR_MISSING_DATA": "No hay datos disponibles para esta fecha. ¡Disculpa las molestias!",
"API_ERROR_FETCHING_DATA": "Lamentablemente, no podemos mostrar ahora la previsión de precios, a causa de una incidencia. Esperamos que se pueda resolver en seguida y poder mostrarla lo más pronto posible. ¡Disculpa las molestias!",
"15YEARS_CAMPAIGN": "¡Celebramos 15 años!",
"15YEARS_DESCRIPTION": "De 100 a 0 €: contrata la luz sin asociarte"
"15YEARS_DESCRIPTION": "De 100 a 0 €: contrata la luz sin asociarte",
"SIMULATION_PRICES_TITLE": "Precio estimado",
"SIMULATION_PRICES_BODY": "El consumo medio de un contrato con tu potencia es de {{ estimated_monthly_kwh }} kWh. Teniendo en cuenta la tarifa escogida, el precio medio del mes pasado y los impuestos vigentes, el coste estimado sería de {{ estimated_monthly_total_eur }} €. Este importe es una estimación orientativa de tu facturación mensual y puede variar según la compensación de excedentes, perfiles de consumo y otras variables. No refleja el importe real final de tu factura a Som Energia. Para una comparativa más ajustada a tu consumo final, escribe a <a target=\"_blank\" href=\"mailto:hola@somenergia.coop\">hola@somenergia.coop</a> y te ayudaremos encantadas."
}
4 changes: 3 additions & 1 deletion src/i18n/locale-eu.json
Original file line number Diff line number Diff line change
Expand Up @@ -859,5 +859,7 @@
"PRICES_ERROR_MISSING_DATA": "Ez dago egun honetako daturik. Barkatu eragozpenak!",
"API_ERROR_FETCHING_DATA": "Tamalez, intzidentzia bat dela eta, une honetan ezin dugu erakutsi prezio-iragarpena. Espero dugu berehala konpontzea eta iragarpena lehenbailehen erakutsi ahal izatea. Barkatu eragozpenak!",
"15YEARS_CAMPAIGN": "15 urte ospatzen ditugu!",
"15YEARS_DESCRIPTION": "100 ordez 0 €: kontratatu argia bazkidetu gabe"
"15YEARS_DESCRIPTION": "100 ordez 0 €: kontratatu argia bazkidetu gabe",
"SIMULATION_PRICES_TITLE": "",
"SIMULATION_PRICES_BODY": ""
}
4 changes: 3 additions & 1 deletion src/i18n/locale-gl.json
Original file line number Diff line number Diff line change
Expand Up @@ -858,5 +858,7 @@
"PRICES_ERROR_MISSING_DATA": "Non hai datos dispoñibles para esta data. Desculpa as molestias!",
"API_ERROR_FETCHING_DATA": "Lamentablemente, nestes intres non che podemos amosar a previsión de prezos debido a unha incidencia. Agardamos resolvelo axiña e poder amosala o antes posible. Desculpa as molestias!",
"15YEARS_CAMPAIGN": "Celebramos 15 anos!",
"15YEARS_DESCRIPTION": "De 100 a 0 €: contrata a luz sen te asociares"
"15YEARS_DESCRIPTION": "De 100 a 0 €: contrata a luz sen te asociares",
"SIMULATION_PRICES_TITLE": "",
"SIMULATION_PRICES_BODY": ""
}
34 changes: 23 additions & 11 deletions src/services/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -227,23 +227,35 @@ export const getPrices = async ({
max_power,
vat = VAT,
cnae = CNAE,
city_id
city_id,
powers,
pricelist_type,
}) => {

const params = new URLSearchParams()

params.append('tariff', tariff)
params.append('max_power', max_power)
params.append('vat', vat)
params.append('cnae', cnae)
params.append('city_id', city_id)

powers?.forEach((power) => {
params.append('powers', power)
})

if (pricelist_type) {
params.append('pricelist_type', pricelist_type)
}

return axios({
method: 'GET',
url: `${WEBFORMS_API_URL}/data/prices`,
params: {
tariff,
max_power,
vat,
cnae,
city_id
}
}).then((response) => {
return response?.data
})
params,
}).then((response) => response?.data)
}


export const newContract = async (data) => {
return axios({
method: 'POST',
Expand Down
Loading