-
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
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
d0dd877
Add styling of edit/add worker component inside drawer
mbielech a386143
Add first test
mbielech d335c98
Changes names of contractTypes to match english equivalents
mbielech 7077c57
Resolve review comments. Add tests
mbielech 073cd58
Import capitalize from string helper
mbielech 5aa70cb
Start tests with loading the file with initial state
mbielech b1f488b
TASK-167 eliminate edit menu from worker-info drawer
Dimonium-239 5ecd487
TASK-167 Delete tests
mbielech 617f549
Merge branch 'develop' into TASK-167-worker-edit-and-add
pectom 4bb37a3
Add changes after review
mbielech 1712e67
Add last change from review
mbielech 9fa737b
Merge branch 'develop' into TASK-167-worker-edit-and-add
pectom File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
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.
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
@maciekb05
Na razie w celach developmentu można ustawić w tym miejscu na sztywno
EditMode
https://github.com/Project-Summer-AI-Lab-Glider/nurse-scheduling-problem-frontend/blob/b3cd626e7e08318b7a0c3a3f3433ddb9b6c195c5/src/components/namestable/nametable-section.component.tsx#L19
Ja będę wprowadzać teraz te dwa róźne tryby i dodam jakieś rozrózróźnienie między nimi