guesstimate/client/src/routes/project/params-tab.tsx

127 lines
5.1 KiB
TypeScript
Raw Normal View History

2020-07-09 13:00:42 +02:00
import React, { FunctionComponent, Fragment, useState, ChangeEvent, MouseEvent } from "react";
2020-04-21 20:45:47 +02:00
import { Project } from "../../models/project";
2020-04-22 22:07:52 +02:00
import { ProjectReducerActions, updateParam } from "../../hooks/use-project-reducer";
import { getRoundUpEstimations, getCurrency, getTimeUnit, getHideFinancialPreviewOnPrint } from "../../models/params";
2020-04-21 20:45:47 +02:00
import TaskCategoriesTable from "./task-categories-table";
2020-07-09 13:00:42 +02:00
import { useHistory } from "react-router";
2020-04-22 23:18:18 +02:00
import { getProjectStorageKey } from "../../util/storage";
2020-04-21 20:45:47 +02:00
export interface ParamsTabProps {
project: Project
dispatch: (action: ProjectReducerActions) => void
}
2020-07-09 13:00:42 +02:00
const ParamsTab: FunctionComponent<ParamsTabProps> = ({ project, dispatch }) => {
2020-04-22 23:18:18 +02:00
const [ deleteButtonEnabled, setDeleteButtonEnabled ] = useState(false);
2020-07-09 13:00:42 +02:00
const history = useHistory();
2020-04-22 23:18:18 +02:00
2020-07-09 13:00:42 +02:00
const onEnableDeleteButtonChange = (evt: ChangeEvent) => {
2020-04-22 23:18:18 +02:00
const checked = (evt.currentTarget as HTMLInputElement).checked;
setDeleteButtonEnabled(checked);
}
2020-07-09 13:00:42 +02:00
const onRoundUpChange = (evt: ChangeEvent) => {
2020-04-22 23:18:18 +02:00
const checked = (evt.currentTarget as HTMLInputElement).checked;
dispatch(updateParam("roundUpEstimations", checked));
2020-04-21 20:45:47 +02:00
};
2020-07-09 13:00:42 +02:00
const onHideFinancialPreview = (evt: ChangeEvent) => {
const checked = (evt.currentTarget as HTMLInputElement).checked;
dispatch(updateParam("hideFinancialPreviewOnPrint", checked));
};
2020-07-09 13:00:42 +02:00
const onCurrencyChange = (evt: ChangeEvent) => {
2020-04-22 23:18:18 +02:00
const value = (evt.currentTarget as HTMLInputElement).value;
dispatch(updateParam("currency", value));
2020-04-21 20:45:47 +02:00
};
const timeUnit = getTimeUnit(project);
2020-07-09 13:00:42 +02:00
const onTimeUnitLabelChange = (evt: ChangeEvent) => {
2020-04-22 23:18:18 +02:00
const value = (evt.currentTarget as HTMLInputElement).value;
dispatch(updateParam("timeUnit", { ...timeUnit, label: value }));
2020-04-21 20:45:47 +02:00
};
2020-07-09 13:00:42 +02:00
const onTimeUnitAcronymChange = (evt: ChangeEvent) => {
2020-04-22 23:18:18 +02:00
const value = (evt.currentTarget as HTMLInputElement).value;
dispatch(updateParam("timeUnit", { ...timeUnit, acronym: value }));
};
2020-07-09 13:00:42 +02:00
const onDeleteProjectClick = (evt: MouseEvent) => {
2020-04-22 23:18:18 +02:00
const projectStorageKey = getProjectStorageKey(project.id);
window.localStorage.removeItem(projectStorageKey);
2020-07-09 13:00:42 +02:00
history.push('/');
2020-04-21 20:45:47 +02:00
};
return (
<Fragment>
2020-07-09 13:00:42 +02:00
<label className="label is-size-5">Impression</label>
<div className="field">
<input type="checkbox"
id="hideFinancialPreview"
name="hideFinancialPreview"
2020-07-09 13:00:42 +02:00
className="switch"
onChange={onHideFinancialPreview}
checked={getHideFinancialPreviewOnPrint(project)} />
2020-07-09 13:00:42 +02:00
<label htmlFor="hideFinancialPreview">Cacher le prévisionnel financier lors de l'impression</label>
</div>
<hr />
2020-07-09 13:00:42 +02:00
<div className="field">
<label className="label is-size-5">Unité de temps</label>
<div className="control">
<input className="input" type="text"
2020-04-21 20:45:47 +02:00
onChange={onTimeUnitLabelChange}
value={timeUnit.label} />
</div>
2020-07-09 13:00:42 +02:00
<label className="label is-size-6">Acronyme</label>
<div className="control">
<input className="input" type="text"
2020-04-21 20:45:47 +02:00
onChange={onTimeUnitAcronymChange}
value={timeUnit.acronym} />
</div>
</div>
2020-07-09 13:00:42 +02:00
<div className="field">
2020-04-22 23:18:18 +02:00
<input type="checkbox"
id="roundUpEstimations"
name="roundUpEstimations"
2020-07-09 13:00:42 +02:00
className="switch"
2020-04-22 23:18:18 +02:00
onChange={onRoundUpChange}
checked={getRoundUpEstimations(project)} />
2020-07-09 13:00:42 +02:00
<label htmlFor="roundUpEstimations">Arrondir les estimations de temps à l'entier supérieur</label>
2020-04-22 23:18:18 +02:00
</div>
2020-04-21 20:45:47 +02:00
<hr />
2020-07-09 13:00:42 +02:00
<div className="field">
<label className="label is-size-5">Devise</label>
<div className="control">
<input className="input" type="text"
2020-04-21 20:45:47 +02:00
onChange={onCurrencyChange}
value={getCurrency(project)} />
</div>
</div>
<hr />
<TaskCategoriesTable project={project} dispatch={dispatch} />
2020-04-22 23:18:18 +02:00
<hr />
<div>
2020-07-09 13:00:42 +02:00
<label className="label is-size-5">Supprimer le projet</label>
<div className="field">
2020-04-22 23:18:18 +02:00
<input type="checkbox"
id="enableDeleteButton"
name="enableDeleteButton"
2020-07-09 13:00:42 +02:00
className="switch is-warning"
2020-04-22 23:18:18 +02:00
onChange={onEnableDeleteButtonChange}
checked={deleteButtonEnabled} />
2020-07-09 13:00:42 +02:00
<label htmlFor="enableDeleteButton">Supprimer ce projet ?</label>
2020-04-22 23:18:18 +02:00
</div>
2020-07-09 13:00:42 +02:00
<button className="button is-danger"
2020-04-22 23:18:18 +02:00
onClick={onDeleteProjectClick}
disabled={!deleteButtonEnabled}>
🗑 Supprimer
</button>
</div>
<hr />
2020-04-21 20:45:47 +02:00
</Fragment>
);
};
export default ParamsTab;