Skip to content

Commit

Permalink
Added localization and many other improvements
Browse files Browse the repository at this point in the history
- Added i18n
- Added new component locale selector to choose it or en language
- Translated all labels from it to en
- Fixed employee net calculation with low gross amount
- Other little improvements
  • Loading branch information
marcomd committed Nov 9, 2022
1 parent 400c213 commit d3fd947
Show file tree
Hide file tree
Showing 23 changed files with 474 additions and 137 deletions.
108 changes: 108 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,12 @@
"preview": "vite preview"
},
"dependencies": {
"i18next": "^22.0.4",
"i18next-browser-languagedetector": "^7.0.1",
"react": "18.2.0",
"react-dom": "18.2.0",
"react-error-boundary": "3.1.4",
"react-i18next": "^12.0.0",
"react-share": "^4.4.1",
"styled-components": "5.3.6"
},
Expand Down
54 changes: 23 additions & 31 deletions src/components/App.tsx
Original file line number Diff line number Diff line change
@@ -1,29 +1,18 @@
import { useState, useEffect, useMemo } from "react";
import styled from "styled-components";
import { ErrorBoundary } from "react-error-boundary";
import { GenericErrorFallback } from "./Errors";

import { Tabs, TabLink, TabContent } from "./base/Tabs";
import FreelanceForm from "./FreelanceForm";
import CompanyForm from "./CompanyForm";
import EmployeeForm from "./EmployeeForm";
import { GenericErrorFallback } from "./Errors";
import { Tabs, TabLink, TabContent } from "./Tabs";
import Header from "./layout/Header";
import Footer from "./layout/Footer";
//import Privacy from "./Privacy";

// --- STYLE ---
const StyledApp = styled.div`
text-align: center;
padding: 0rem 2rem;
max-width: 700px;
margin: 0 auto;
import LocaleSelector from "./base/LocaleSelector";
import { StyledApp } from "./styled/StyledApp";

@media only screen and (max-width: 550px) {
padding: 0rem 0.4rem;
}
`;
import { useTranslation } from "react-i18next";

// --- CODE ---
export default function App() {
const media: MediaQueryList = useMemo(() => {
return window.matchMedia("(max-width: 580px)")
Expand All @@ -39,25 +28,28 @@ export default function App() {
return () => media.removeEventListener("change", (e) => setMobile(e.matches));
}, []);

const { t } = useTranslation();

return (
<StyledApp>
<Header mobile={mobile} />
<Header mobile={mobile}>{t('title')}</Header>
<ErrorBoundary FallbackComponent={GenericErrorFallback}>
<LocaleSelector />
<Tabs defaults="employee">
<TabLink to="employee">Dipendente</TabLink>
<TabLink to="freelance">Professionista</TabLink>
<TabLink to="company">Azienda</TabLink>

<TabContent id="employee">
<EmployeeForm />
</TabContent>
<TabContent id="freelance">
<FreelanceForm />
</TabContent>
<TabContent id="company">
<CompanyForm />
</TabContent>
</Tabs>
<TabLink to="employee">{t('employee.name')}</TabLink>
<TabLink to="freelance">{t('freelance.name')}</TabLink>
<TabLink to="company">{t('company.name')}</TabLink>

<TabContent id="employee">
<EmployeeForm />
</TabContent>
<TabContent id="freelance">
<FreelanceForm />
</TabContent>
<TabContent id="company">
<CompanyForm />
</TabContent>
</Tabs>
</ErrorBoundary>
<Footer />
</StyledApp>
Expand Down
21 changes: 11 additions & 10 deletions src/components/CompanyForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ import {
StyledResultMainRow
} from "./styled/StyledForm";

import { useTranslation } from "react-i18next";

const initialAmounts: TaxesOutcome = {
netAmount: 0,
iresAmount: 0,
Expand All @@ -36,6 +38,7 @@ export default function Form() {
const refResult = useRef<HTMLInputElement>(null);

const [errors, dispatchErrors] = useReducer(reducerErrors, initialErrors);
const { t } = useTranslation();

// useEffect(() => {
// console.log(`errors`, errors);
Expand All @@ -48,7 +51,7 @@ export default function Form() {
//const deductibleAmount = event.target.elements.deductibleAmount.value;
//console.log(`grossAmount:${grossAmount} deductibleAmount:${deductibleAmount}`);

if (!checkErrors({ grossAmount, deductibleAmount, dispatchErrors })) return;
if (!checkErrors({ grossAmount, deductibleAmount, dispatchErrors, t })) return;

const { netAmount, iresAmount, irapAmount }: TaxesOutcome = calculateTaxes(
grossAmount,
Expand All @@ -71,15 +74,14 @@ export default function Form() {

return (
<StyledContainer>
<h3>Calcolo al netto di IRAP e IRES</h3>
<form>
<div ref={refResult}></div>
<StyledFormRow>
<div ref={refResult}></div>
<h3>{ t('company.title') }</h3>
<StyledFormRow>
<span className="input-symbol input-symbol-euro">
<StyledTextInput
type="text"
id="grossAmount"
placeholder="Lordo"
placeholder={t('inputs.placeholders.grossAmount')}
onChange={(e) => setGrossAmount(parseInt(e.target.value))}
/>
</span>
Expand All @@ -91,7 +93,7 @@ export default function Form() {
<StyledTextInput
type="text"
id="deductibleAmount"
placeholder="Spese detraibili"
placeholder={t('inputs.placeholders.deductibleAmount')}
onChange={(e) => setDeductibleAmount(parseInt(e.target.value))}
/>
</span>
Expand All @@ -107,15 +109,14 @@ export default function Form() {
IRAP: {numberFormatter.format(outcomeAmounts.irapAmount)}
</StyledResultNormalRow>
<StyledResultMainRow>
Netto: <b>{numberFormatter.format(outcomeAmounts.netAmount)}</b>
{t('result.netAmount')}: <b>{numberFormatter.format(outcomeAmounts.netAmount)}</b>
</StyledResultMainRow>
<StyledResultNormalRow>
Netto mese:{" "}
{t('result.netAmountPerMonth')}:&nbsp;
{numberFormatter.format(outcomeAmounts.netAmount / 12)}
</StyledResultNormalRow>
</StyledResultContainer>
)}
</form>
</StyledContainer>
);
}
Loading

1 comment on commit d3fd947

@vercel
Copy link

@vercel vercel bot commented on d3fd947 Nov 9, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

lordo-netto – ./

lordo-netto-marcomd.vercel.app
lordo-netto-git-main-marcomd.vercel.app
lordo-netto.vercel.app

Please sign in to comment.