Skip to content

Commit

Permalink
Fixed issue where a postal code starting with 0 issue #113
Browse files Browse the repository at this point in the history
  • Loading branch information
xXBJXx committed Jan 3, 2023
1 parent c5e95bf commit 7ffd9d0
Show file tree
Hide file tree
Showing 20 changed files with 168 additions and 137 deletions.
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
NodeJS v14 or higher is required.

## Migration Guides
[Migration guide to 3.3.x](docs/guide/migration_3.3.x.md)\
[Migration guide to 3.3.4](docs/guide/migration_3.3.4.md)\
[Migration guide to 3.3.3](docs/guide/migration_3.3.x.md)\
[Migration guide to 3.1.x](docs/guide/migration_3.1.x.md)

## Documentation
Expand All @@ -26,6 +27,9 @@ NodeJS v14 or higher is required.
Placeholder for the next version (at the beginning of the line):
### __WORK IN PROGRESS__ (- falls nicht benötigt löschen sonst klammern entfernen und nach dem - dein text schreiben)
-->
### __WORK IN PROGRESS__
* (xXBJXx) Fixed an issue where a postal code starting with 0 was not displayed correctly [Issue #113](https://github.com/iobroker-community-adapters/ioBroker.tankerkoenig/issues/113)

### 3.3.3 (2023-01-02)
* (xXBJXx) fixed => adapter does not fetch data after a `requestData error` e.g. internet termination.
* (xXBJXx) add adapter migration Guide from 3.1.x to 3.3.x or 3.2.x to 3.3.x [Migration guide](docs/guide/migration_3.3.x.md)
Expand Down
18 changes: 9 additions & 9 deletions admin/build/index.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions admin/build/index.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion admin/src/Modal/AddModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export const AddModal: React.FC<AddModalProps> = ({
city: '',
discountObj: { discount: 0, discountType: '', fuelType: [] },
discounted: false,
postCode: 0,
postCode: '',
station: '',
stationname: '',
street: '',
Expand Down
1 change: 0 additions & 1 deletion admin/src/SettingPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ export const SettingPage: React.FC<SettingPageProps> = ({ onChange, settings, se
});
}
};

//add row
const handleAdd = async (value: ioBroker.Station): Promise<void> => {
newRow = [...settings.station];
Expand Down
45 changes: 32 additions & 13 deletions admin/src/component/AddStationDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export const AddStationDialog: React.FC<RowProps> = ({ addRow }): JSX.Element =>
stationname: '',
street: '',
city: '',
postCode: 0,
postCode: '',
houseNumber: '',
discounted: false,
discountObj: {
Expand All @@ -83,7 +83,7 @@ export const AddStationDialog: React.FC<RowProps> = ({ addRow }): JSX.Element =>
const [copyValid, setCopyValid] = useState(false);
const [street, setStreet] = useState<string>('');
const [city, setCity] = useState<string>('');
const [postCode, setPostCode] = useState<number>(0);
const [postCode, setPostCode] = useState<string>('');
const [houseNumber, setHouseNumber] = useState<string>('');

useEffect(() => {
Expand Down Expand Up @@ -128,7 +128,24 @@ export const AddStationDialog: React.FC<RowProps> = ({ addRow }): JSX.Element =>
});
setCity(result.city);
setHouseNumber(result.houseNumber);
setPostCode(result.postCode);

if (result.postCode) {
result.postCode = result.postCode.toString();
if (result.postCode !== '') {
// check if the zip code has 5 digits
if (result.postCode.length === 5) {
setPostCode(result.postCode);
} else {
// setze der postleitzahl eine 0 voran
setPostCode('0' + result.postCode);
}
} else {
setPostCode('');
}
} else {
setPostCode('');
}

setStreet(result.street);
}
} else {
Expand Down Expand Up @@ -161,11 +178,14 @@ export const AddStationDialog: React.FC<RowProps> = ({ addRow }): JSX.Element =>
const handleChangePostCode = (event: React.ChangeEvent<HTMLTextAreaElement | HTMLInputElement>): void => {
const newPostCode: string = event.target.value;
if (newPostCode !== '') {
setPostCode(parseInt(newPostCode));
setNewRow({ ...newRow, postCode: parseInt(newPostCode) });
// check if the input consists of numbers only
if (newPostCode.match(/^[0-9]+$/)) {
setPostCode(newPostCode);
setNewRow({ ...newRow, postCode: newPostCode });
}
} else {
setPostCode(0);
setNewRow({ ...newRow, postCode: 0 });
setPostCode('');
setNewRow({ ...newRow, postCode: '' });
}
};

Expand Down Expand Up @@ -468,7 +488,7 @@ export const AddStationDialog: React.FC<RowProps> = ({ addRow }): JSX.Element =>
>
<React.Fragment>
<Tooltip
title={_('tooltipStationName')}
title={_('tooltipStationStreet')}
arrow
placement={'top'}
enterNextDelay={500}
Expand Down Expand Up @@ -518,7 +538,7 @@ export const AddStationDialog: React.FC<RowProps> = ({ addRow }): JSX.Element =>
/>
</Tooltip>
<Tooltip
title={_('tooltipStationName')}
title={_('tooltipStationCity')}
arrow
placement={'top'}
enterNextDelay={500}
Expand All @@ -543,7 +563,7 @@ export const AddStationDialog: React.FC<RowProps> = ({ addRow }): JSX.Element =>
/>
</Tooltip>
<Tooltip
title={_('tooltipStationName')}
title={_('tooltipStationZip')}
arrow
placement={'top'}
enterNextDelay={500}
Expand All @@ -552,15 +572,14 @@ export const AddStationDialog: React.FC<RowProps> = ({ addRow }): JSX.Element =>
<TextField
label={_('stationZip')}
value={postCode.toString()}
type={'number'}
type={'text'}
margin={'normal'}
sx={{
width: '15ch',
}}
placeholder={'10910'}
inputProps={{
maxLength: 6,
min: 0,
maxLength: 5,
style: { textAlign: 'center' },
}}
onChange={(event) => {
Expand Down
36 changes: 28 additions & 8 deletions admin/src/component/EditTableDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export const EditTableDialog: React.FC<RowProps> = ({ editRow, oldRow, checkAler
stationname: '',
street: '',
city: '',
postCode: 0,
postCode: '',
houseNumber: '',
discounted: false,
discountObj: {
Expand All @@ -80,7 +80,7 @@ export const EditTableDialog: React.FC<RowProps> = ({ editRow, oldRow, checkAler
const [name, setName] = useState<string>(oldRow.stationname);
const [street, setStreet] = useState<string>(oldRow.street || '');
const [city, setCity] = useState<string>(oldRow.city || '');
const [postCode, setPostCode] = useState<number>(oldRow.postCode || 0);
const [postCode, setPostCode] = useState<string>(oldRow.postCode || '');
const [houseNumber, setHouseNumber] = useState<string>(oldRow.houseNumber || '');
const [discountType, setDiscountType] = useState<string>(oldRow.discountObj.discountType);
const [discount, setDiscount] = useState<number>(oldRow.discountObj.discount);
Expand Down Expand Up @@ -146,9 +146,26 @@ export const EditTableDialog: React.FC<RowProps> = ({ editRow, oldRow, checkAler
});
setCity(result.city);
setHouseNumber(result.houseNumber);
setPostCode(result.postCode);

if (result.postCode) {
result.postCode = result.postCode.toString();
if (result.postCode !== '') {
// check if the zip code has 5 digits
if (result.postCode.length === 5) {
setPostCode(result.postCode);
} else {
// setze der postleitzahl eine 0 voran
setPostCode('0' + result.postCode);
}
} else {
setPostCode('');
}
} else {
setPostCode('');
}
setStreet(result.street);
}

setValid(false);
} else {
setValid(true);
Expand Down Expand Up @@ -204,11 +221,14 @@ export const EditTableDialog: React.FC<RowProps> = ({ editRow, oldRow, checkAler
const handleChangePostCode = (event: React.ChangeEvent<HTMLTextAreaElement | HTMLInputElement>): void => {
const newPostCode: string = event.target.value;
if (newPostCode !== '') {
setPostCode(parseInt(newPostCode));
setEditRow({ ...newEditRow, postCode: parseInt(newPostCode) });
// check if the input consists of numbers only
if (newPostCode.match(/^[0-9]+$/)) {
setPostCode(newPostCode);
setEditRow({ ...newEditRow, postCode: newPostCode });
}
} else {
setPostCode(0);
setEditRow({ ...newEditRow, postCode: 0 });
setPostCode('');
setEditRow({ ...newEditRow, postCode: '' });
}
};
const handleChangeHouseNumber = (
Expand Down Expand Up @@ -593,7 +613,7 @@ export const EditTableDialog: React.FC<RowProps> = ({ editRow, oldRow, checkAler
}}
placeholder={'10910'}
inputProps={{
maxLength: 6,
maxLength: 5,
style: { textAlign: 'center' },
}}
onChange={(event) => {
Expand Down
8 changes: 3 additions & 5 deletions admin/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ const migrateSettings = (settings: ioBroker.AdapterConfig) => {
if (settings.station === undefined) {
settings.station = [];
}
if (settings.station !== undefined) {
if (settings.station.length !== 0) {
settings.station.map((stationValue, index) => {
if (stationValue.station === undefined) {
settings.station[index].station = '';
Expand All @@ -76,11 +76,9 @@ const migrateSettings = (settings: ioBroker.AdapterConfig) => {
if (stationValue.street === undefined) {
settings.station[index].street = '';
}
if (typeof stationValue.postCode === 'string') {
settings.station[index].postCode = parseInt(stationValue.postCode);
}

if (stationValue.postCode === undefined) {
settings.station[index].postCode = 0;
settings.station[index].postCode = '';
}
if (stationValue.city === undefined) {
settings.station[index].city = '';
Expand Down
2 changes: 1 addition & 1 deletion admin/src/lib/DetailRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export interface RequestDetailProps {
street: string;
city: string;
houseNumber: string;
postCode: number;
postCode: string;
latitude: number;
longitude: number;
wholeDay: boolean;
Expand Down
4 changes: 2 additions & 2 deletions build/lib/object_definition.js

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

Loading

0 comments on commit 7ffd9d0

Please sign in to comment.