-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add styling of edit/add worker component inside drawer #128
Changes from 8 commits
d0dd877
a386143
d335c98
7077c57
073cd58
5aa70cb
b1f488b
5ecd487
617f549
4bb37a3
1712e67
9fa737b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,162 @@ | ||
import { ContractType, WorkerInfoModel, WorkerType } from "../../common-models/worker-info.model"; | ||
import React, { useState } from "react"; | ||
import { makeStyles } from "@material-ui/core/styles"; | ||
import { Grid, Input, TextField, Typography } from "@material-ui/core"; | ||
import { DropdownButtons } from "../common-components/dropdown-buttons/dropdown-buttons.component"; | ||
import { | ||
translateAndCapitalizeContractType, | ||
translateAndCapitalizeWorkerType, | ||
} from "./worker-edit.helper"; | ||
import MaskedInput from "react-text-mask"; | ||
import { Button } from "../common-components"; | ||
|
||
const useStyles = makeStyles({ | ||
container: { | ||
height: "100%", | ||
}, | ||
label: { | ||
fontSize: 16, | ||
fontWeight: 700, | ||
lineHeight: 1.75, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To też bym dał do stałych |
||
}, | ||
}); | ||
|
||
export interface WorkerInfoExtendedInterface { | ||
name: string; | ||
workerType: WorkerType | undefined; | ||
contractType: ContractType | undefined; | ||
employmentTime: string; | ||
civilTime: string; | ||
} | ||
|
||
export function WorkerEditComponent(info: WorkerInfoModel): JSX.Element { | ||
const classes = useStyles(); | ||
|
||
const [workerInfo, setWorkerInfo] = useState<WorkerInfoExtendedInterface>({ | ||
name: info.name, | ||
workerType: info.type, | ||
contractType: undefined, | ||
employmentTime: " / ", | ||
civilTime: "0", | ||
}); | ||
|
||
function handleUpdate(event) { | ||
const { target } = event; | ||
updateWorkerInfo(target.name, target.value); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Imo tak jest ładniej function handleUpdate(event) {
const { name, value } = event.target;
updateWorkerInfo(name, value);
} |
||
} | ||
|
||
function updateWorkerInfo(key, value) { | ||
setWorkerInfo({ ...workerInfo, [key]: value }); | ||
} | ||
|
||
const positionOptions = Object.keys(WorkerType).map((workerTypeName) => { | ||
const workerType = WorkerType[workerTypeName]; | ||
return { | ||
label: translateAndCapitalizeWorkerType(workerType), | ||
action: () => updateWorkerInfo("workerType", workerType), | ||
}; | ||
}); | ||
|
||
const contractOptions = Object.keys(ContractType).map((contractTypeName) => { | ||
const contractType = ContractType[contractTypeName]; | ||
return { | ||
label: translateAndCapitalizeContractType(contractType), | ||
action: () => updateWorkerInfo("contractType", contractType), | ||
}; | ||
}); | ||
|
||
return ( | ||
<Grid container className={classes.container} direction="column" justify="space-between"> | ||
<Grid item> | ||
<Grid container direction="column" spacing={5}> | ||
<Grid item xs={9}> | ||
<Typography className={classes.label}>Imię i nazwisko</Typography> | ||
<TextField | ||
fullWidth | ||
name="name" | ||
data-cy="name" | ||
value={workerInfo.name} | ||
onChange={handleUpdate} | ||
color="primary" | ||
/> | ||
</Grid> | ||
<Grid item xs={6}> | ||
<Typography className={classes.label}>Stanowisko</Typography> | ||
<DropdownButtons | ||
data-cy="position" | ||
buttons={positionOptions} | ||
mainLabel={ | ||
workerInfo.workerType | ||
? translateAndCapitalizeWorkerType(workerInfo.workerType) | ||
: "Stanowisko" | ||
} | ||
variant="outlined" | ||
/> | ||
</Grid> | ||
<Grid item xs={6}> | ||
<Typography className={classes.label}>Wymiar pracy</Typography> | ||
<DropdownButtons | ||
data-cy="contract" | ||
buttons={contractOptions} | ||
mainLabel={ | ||
workerInfo.contractType | ||
? translateAndCapitalizeContractType(workerInfo.contractType) | ||
: "Typ umowy" | ||
} | ||
variant="outlined" | ||
/> | ||
</Grid> | ||
{workerInfo.contractType === ContractType.EMPLOYMENT_CONTRACT && ( | ||
<Grid item xs={6}> | ||
<Typography className={classes.label}>Wpisz wymiar etatu</Typography> | ||
<TextField | ||
fullWidth | ||
name="civilTime" | ||
data-cy="civilTime" | ||
value={workerInfo.civilTime} | ||
type="number" | ||
onChange={handleUpdate} | ||
color="primary" | ||
/> | ||
</Grid> | ||
)} | ||
{workerInfo.contractType === ContractType.CIVIL_CONTRACT && ( | ||
<Grid item xs={6}> | ||
<Typography className={classes.label}>Ilość godzin</Typography> | ||
<Input | ||
fullWidth | ||
name="employmentTime" | ||
value={workerInfo.employmentTime} | ||
onChange={handleUpdate} | ||
data-cy="hours-number" | ||
inputComponent={TextMaskCustom as any} | ||
/> | ||
</Grid> | ||
)} | ||
</Grid> | ||
</Grid> | ||
<Grid item> | ||
<Button>Zapisz pracownika</Button> | ||
</Grid> | ||
</Grid> | ||
); | ||
} | ||
|
||
interface TextMaskCustomProps { | ||
inputRef: (ref: HTMLInputElement | null) => void; | ||
} | ||
|
||
function TextMaskCustom(props: TextMaskCustomProps) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Taki komponent dałbym do folderu ze wspólnymi komponentami, bo może gdzieś będziemy tego reużywać |
||
const { inputRef, ...other } = props; | ||
|
||
return ( | ||
<MaskedInput | ||
{...other} | ||
ref={(ref: any) => { | ||
inputRef(ref ? ref.inputElement : null); | ||
}} | ||
mask={[/[1-9]/, "/", /[1-9]/]} | ||
showMask | ||
/> | ||
); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { | ||
WorkerTypeHelper, | ||
WorkerType, | ||
ContractType, | ||
ContractTypeHelper, | ||
} from "../../common-models/worker-info.model"; | ||
import { StringHelper } from "../../helpers/string.helper"; | ||
|
||
export function translateAndCapitalizeWorkerType(workerType: WorkerType): string { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nie umieszczamy helperów w komponentach. Jeśli kod jest wykorzystywany w jednym komponencie to dodajemy go tylko tam. Jeśli może pojawić się potrzeba ponownego wykorzystania to należy to wrzucić do folderu jakiegoś istniejącego helpera z helpers albo dodać nowego. |
||
const translation = WorkerTypeHelper.translate(workerType); | ||
return StringHelper.capitalize(translation); | ||
} | ||
|
||
export function translateAndCapitalizeContractType(contractType: ContractType): string { | ||
const translation = ContractTypeHelper.translate(contractType); | ||
return StringHelper.capitalize(translation); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ import React from "react"; | |
import Drawer, { DrawerOptions } from "../../common-components/drawer/drawer.component"; | ||
import { WorkerInfoModel } from "../../../common-models/worker-info.model"; | ||
import { WorkerInfoComponent } from "../../namestable/worker-info.component"; | ||
import { WorkerEditComponent } from "../../namestable/worker-edit.component"; | ||
|
||
export enum WorkerDrawerMode { | ||
EDIT, | ||
|
@@ -29,9 +30,10 @@ export default function WorkerDrawerComponent(options: WorkerDrawerOptions): JSX | |
const { mode, worker, setOpen, ...otherOptions } = options; | ||
const title = getTitle(mode); | ||
const isInfo = mode === WorkerDrawerMode.INFO; | ||
const isEdit = mode === WorkerDrawerMode.EDIT; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @maciekb05 Ja będę wprowadzać teraz te dwa róźne tryby i dodam jakieś rozrózróźnienie między nimi |
||
return ( | ||
<Drawer setOpen={setOpen} title={title} {...otherOptions}> | ||
{worker && <h1>{worker.name}</h1>} | ||
{isEdit && worker && <WorkerEditComponent {...worker} />} | ||
|
||
{isInfo && WorkerInfoComponent(worker ?? { name: "", time: 0 })} | ||
</Drawer> | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Size jest w stałych w plikach scss