Skip to content
This repository has been archived by the owner on Sep 16, 2024. It is now read-only.

Commit

Permalink
minor revision done, ready for another review
Browse files Browse the repository at this point in the history
  • Loading branch information
kcaparas1630 committed Jun 22, 2024
1 parent 7fd80df commit 12f0263
Show file tree
Hide file tree
Showing 9 changed files with 56 additions and 60 deletions.
1 change: 0 additions & 1 deletion frontend/package-lock.json

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

1 change: 0 additions & 1 deletion frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
"bootstrap": "^5.3.3",
"eslint-config-airbnb-base": "^15.0.0",
"formik": "^2.4.6",
"prop-types": "^15.8.1",
"react": "^18.2.0",
"react-bootstrap": "^2.10.2",
"react-dom": "^18.2.0",
Expand Down
5 changes: 3 additions & 2 deletions frontend/src/Commons/Button/Button.style.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import styled from '@emotion/styled';
import * as tokens from '@bcgov/design-tokens/js';
import screenSizes from '@Constants/ScreenSize';
import ComponentText from '@Constants/ComponentText';
import getButtonSize from './ButtonSizeConstant';

type StyledButtonProps = {
Expand All @@ -17,7 +18,7 @@ const StyledButton = styled.button<StyledButtonProps>`
max-height: 42px;
height: 100%;
width: 100%;
max-width: ${(props) => getButtonSize(props.size, false)};
max-width: ${(props) => getButtonSize(props.size, ComponentText.ISMOBILE)};
background-color: ${(props) => (props.actions === 'primary'
? tokens.surfaceColorPrimaryButtonDefault
: tokens.surfaceColorSecondaryButtonDefault)};
Expand All @@ -35,7 +36,7 @@ const StyledButton = styled.button<StyledButtonProps>`
}
@media (min-width: ${screenSizes.desktop}) {
max-width: ${(props) => getButtonSize(props.size, true)};
max-width: ${(props) => getButtonSize(props.size, ComponentText.ISDESKTOP)};
}
`;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,14 @@ const FieldsAndSoilComponent: React.FC<InputModuleProps> = ({ farmDetails, updat
// Only triggered once, it would show list and persists.
const [isSubmitted, setSubmitted] = useState<boolean>(false);
// Would trigger when new field button is clicked.
const [fieldAdd, setFieldAdd] = useState<boolean>(false);

const [isFieldAdded, setFieldAdd] = useState<boolean>(false);
const validationSchema = Yup.object().shape({
FieldName: Yup.string().max(24).required('Required'),
Area: Yup.number()
.min(1, 'Area should be higher than 1')
.max(100, 'Area should be lower than 100')
.required('Required'),
Comments: Yup.string().max(200, 'Comments should be lower than 200'),
Comments: Yup.string().max(200, 'Comments should be lower than 200 chars'),
});
/**
*
Expand All @@ -53,18 +52,12 @@ const FieldsAndSoilComponent: React.FC<InputModuleProps> = ({ farmDetails, updat
setTimeout(() => {
const farmInfo: FarmDetailsInterface = { ...farmDetails };
farmInfo.Fields.push({
id: fieldIndex,
Id: fieldIndex,
FieldName: values.FieldName,
Area: values.Area,
Comments: values.Comments,
});
const newInitialFieldValues = {
id: fieldIndex,
FieldName: '',
Area: 0,
Comments: '',
};
setInitialFieldValues(newInitialFieldValues);
setInitialFieldValues(farmInfo.Fields[0]);
setFieldsInfo(farmInfo);
setFieldIndex((prevIndex) => prevIndex + 1);
setSubmitted(true);
Expand All @@ -91,15 +84,15 @@ const FieldsAndSoilComponent: React.FC<InputModuleProps> = ({ farmDetails, updat
farmDetails={farmDetails}
updateFarmDetails={updateFarmDetails}
/>
{!fieldAdd && (
{ !isFieldAdded && (
<FieldsButtonComponent
addNewField={addNewField}
submitFarmInfo={submitFarmInfo}
/>
)}
</>
)}
{(fieldAdd || !isSubmitted) && (
{(isFieldAdded || !isSubmitted) && (
<Formik
initialValues={initialFieldValues}
validationSchema={validationSchema}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,14 @@ import Button from '@Commons/Button/Button';
import React from 'react';
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import { faPlus } from '@fortawesome/free-solid-svg-icons';
import PropTypes from 'prop-types';
import {
StyledButtonGroupContainer,
StyledButtonContainer,
StyledAddCancelButtonContainer,
StyledNewFieldButtonContainer,
} from './FieldsButtonComponent.styles';

interface ButtonComponentProps {
type ButtonComponentProps = {
addNewField: () => void;
submitFarmInfo: () => void;
}
Expand All @@ -25,7 +24,7 @@ const FieldsButtonComponent: React.FC<ButtonComponentProps> = ({ addNewField, su
disabled={false}
radius="50px"
actions="secondary"
text={ComponentText.NEWFIELD}
text={ComponentText.ADD_FIELD}
handleClick={addNewField}
>
<FontAwesomeIcon icon={faPlus} />
Expand Down Expand Up @@ -54,9 +53,5 @@ const FieldsButtonComponent: React.FC<ButtonComponentProps> = ({ addNewField, su
</StyledAddCancelButtonContainer>
</StyledButtonGroupContainer>
);
// Props Validation
FieldsButtonComponent.propTypes = {
addNewField: PropTypes.func.isRequired,
submitFarmInfo: PropTypes.func.isRequired,
};

export default FieldsButtonComponent;
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React from 'react';
import InputModuleProps from 'src/Interface/InputModuleProps';
import { faPencil, faTrash } from '@fortawesome/free-solid-svg-icons';
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import FieldDetailInterface from 'src/Interface/FieldDetailsInterface';
import {
StyledListContainer,
StyledListItem,
Expand All @@ -12,40 +13,45 @@ import {
StyledDivider,
} from './FieldsListComponent.styles';

const FieldsListComponent: React.FC<InputModuleProps> = ({ farmDetails }) => (
<StyledFieldInfoList>
{farmDetails.Fields.slice(1).map((fields) => (
<div key={fields.id}>
<StyledListContainer>
<StyledListItem width="30%">
<h2>Field Name</h2>
<p key={fields.FieldName}>{fields.FieldName}</p>
</StyledListItem>
<StyledListItem width="20%">
<h2>Area</h2>
<p key={fields.Area}>{fields.Area}</p>
</StyledListItem>
<StyledCommentContainerDesktop>
<StyledListItem width="90%">
const FieldsListComponent: React.FC<InputModuleProps> = ({ farmDetails }) => {
const fieldCount = farmDetails.Fields.length;
return (
<StyledFieldInfoList>
{farmDetails.Fields.slice(1).map((fields: FieldDetailInterface) => (
<div key={fields.Id}>
<StyledListContainer>
<StyledListItem width="30%">
<h2>Field Name</h2>
<p key={fields.FieldName}>{fields.FieldName}</p>
</StyledListItem>
<StyledListItem width="20%">
<h2>Area</h2>
<p key={fields.Area}>{fields.Area}</p>
</StyledListItem>
<StyledCommentContainerDesktop>
<StyledListItem width="90%">
<h2>Field Comments (optional)</h2>
<p key={fields.Comments}>{fields.Comments}</p>
</StyledListItem>
</StyledCommentContainerDesktop>
<StyledFontAwesomeContainer>
<FontAwesomeIcon icon={faPencil} />
<FontAwesomeIcon icon={faTrash} />
</StyledFontAwesomeContainer>
</StyledListContainer>
<StyledCommentContainerMobile>
<StyledListItem width="100%">
<h2>Field Comments (optional)</h2>
<p key={fields.Comments}>{fields.Comments}</p>
</StyledListItem>
</StyledCommentContainerDesktop>
<StyledFontAwesomeContainer>
<FontAwesomeIcon icon={faPencil} />
<FontAwesomeIcon icon={faTrash} />
</StyledFontAwesomeContainer>
</StyledListContainer>
<StyledCommentContainerMobile>
<StyledListItem width="100%">
<h2>Field Comments (optional)</h2>
<p key={fields.Comments}>{fields.Comments}</p>
</StyledListItem>
</StyledCommentContainerMobile>
<StyledDivider />
</div>
))}
</StyledFieldInfoList>
);
</StyledCommentContainerMobile>
{fieldCount > 2 && (
<StyledDivider />
)}
</div>
))}
</StyledFieldInfoList>
);
};

export default FieldsListComponent;
5 changes: 4 additions & 1 deletion frontend/src/Constants/ComponentText.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@ const ComponentText = {
NEXT: 'Next',
ADD: 'Add',
CANCEL: 'Cancel',
NEWFIELD: 'Add Field',
ADD_FIELD: 'Add Field',
BACK: 'Back',
// For buttonSize arguments. Refer to ButtonSizeConstant.ts
ISDESKTOP: true,
ISMOBILE: false,
};

export default ComponentText;
2 changes: 1 addition & 1 deletion frontend/src/Constants/InitialFarmDetails.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const initialFarmDetails: FarmDetailsInterface = {
FarmName: '',
FarmRegion: '',
HasBerries: true,
Fields: [{ id: 0, FieldName: '', Area: 0, Comments: '' }],
Fields: [{ Id: 0, FieldName: '', Area: 0, Comments: '' }],
};

export default initialFarmDetails;
2 changes: 1 addition & 1 deletion frontend/src/Interface/FieldDetailsInterface.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* @author @GDamaso
*/
interface FieldDetailInterface {
id: number;
Id: number;
FieldName: string;
Area: number;
Comments?: string | null;
Expand Down

0 comments on commit 12f0263

Please sign in to comment.