-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
237 additions
and
6 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
src/components/common-components/text-mask-custom/text-mask-custom.component.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import React from "react"; | ||
import MaskedInput from "react-text-mask"; | ||
|
||
export interface TextMaskCustomProps { | ||
inputRef: (ref: HTMLInputElement | null) => void; | ||
} | ||
|
||
export function TextMaskCustom(props: TextMaskCustomProps): JSX.Element { | ||
const { inputRef, ...other } = props; | ||
|
||
return ( | ||
<MaskedInput | ||
{...other} | ||
ref={(ref: { inputElement: HTMLInputElement }): void => { | ||
inputRef(ref ? ref.inputElement : null); | ||
}} | ||
mask={[/[1-9]/, "/", /[1-9]/]} | ||
showMask | ||
/> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,163 @@ | ||
import { | ||
ContractType, | ||
ContractTypeHelper, | ||
WorkerInfoModel, | ||
WorkerType, | ||
WorkerTypeHelper, | ||
} 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 { Button } from "../common-components"; | ||
import ScssVars from "../../assets/styles/styles/custom/_variables.module.scss"; | ||
import { TextMaskCustom } from "../common-components/text-mask-custom/text-mask-custom.component"; | ||
import { StringHelper } from "../../helpers/string.helper"; | ||
|
||
const useStyles = makeStyles({ | ||
container: { | ||
height: "100%", | ||
}, | ||
label: { | ||
fontSize: ScssVars.fontSizeBase, | ||
fontWeight: 700, | ||
lineHeight: ScssVars.lineHeightXl, | ||
}, | ||
}); | ||
|
||
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): void { | ||
const { name, value } = event.target; | ||
updateWorkerInfo(name, value); | ||
} | ||
|
||
function updateWorkerInfo(key, value): void { | ||
setWorkerInfo({ ...workerInfo, [key]: value }); | ||
} | ||
|
||
const positionOptions = Object.keys(WorkerType).map((workerTypeName) => { | ||
const workerType = WorkerType[workerTypeName]; | ||
return { | ||
label: translateAndCapitalizeWorkerType(workerType), | ||
action: (): void => updateWorkerInfo("workerType", workerType), | ||
}; | ||
}); | ||
|
||
const contractOptions = Object.keys(ContractType).map((contractTypeName) => { | ||
const contractType = ContractType[contractTypeName]; | ||
return { | ||
label: translateAndCapitalizeContractType(contractType), | ||
action: (): void => 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={ | ||
// eslint-disable-next-line | ||
TextMaskCustom as any | ||
} | ||
/> | ||
</Grid> | ||
)} | ||
</Grid> | ||
</Grid> | ||
<Grid item> | ||
<Button>Zapisz pracownika</Button> | ||
</Grid> | ||
</Grid> | ||
); | ||
} | ||
|
||
function translateAndCapitalizeWorkerType(workerType: WorkerType): string { | ||
return translateAndCapitalize(workerType, WorkerTypeHelper); | ||
} | ||
|
||
function translateAndCapitalizeContractType(contractType: ContractType): string { | ||
return translateAndCapitalize(contractType, ContractTypeHelper); | ||
} | ||
|
||
function translateAndCapitalize<T>(what: T, using: { translate: (what: T) => string }): string { | ||
const translation = using.translate(what); | ||
return StringHelper.capitalize(translation); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters