Skip to content

Commit

Permalink
Add indication of door status
Browse files Browse the repository at this point in the history
  • Loading branch information
user890104 committed Feb 18, 2024
1 parent f9c0d1e commit 71677f1
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 4 deletions.
1 change: 1 addition & 0 deletions public/locales/bg.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ views:
door:
locked: Заключено
unlocked: Отключено
open: Отворено
unknown: Неясно
no_access: |
Нямате права за управление на вратите. Моля, свържете се с представител на Управителния съвет на Инит Лаб на адрес
Expand Down
1 change: 1 addition & 0 deletions public/locales/en.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ views:
door:
locked: Locked
unlocked: Unlocked
open: Wide open
unknown: Unknown
no_access: |
You don't have the necessary rights to control the doors. Please contact an init Lab board member at
Expand Down
4 changes: 3 additions & 1 deletion src/pages/Devices.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ const Devices = ({
{filteredDevices.length > 0 ? filteredDevices.map(device => {
const deviceActions = deviceActionMapper(device);
const isUnavailable = device?.statuses?.available === false;
const isOpen = device?.statuses?.open === true;

return (<Col key={device.id}>
<Card>
Expand All @@ -56,7 +57,8 @@ const Devices = ({
{isUnavailable ? t('views.devices.offline') : <>
{deviceActions.map(action =>
<DeviceActionButton key={action} deviceId={device.id} action={action}
busyActionId={busyActionId} setBusyActionId={setBusyActionId} />)}
busyActionId={busyActionId} setBusyActionId={setBusyActionId}
isDoorOpen={isOpen} />)}
{deviceActions.length === 0 && <LoadingIcon large />}
</>}
</Card.Body>
Expand Down
15 changes: 12 additions & 3 deletions src/widgets/DeviceActionButton/DeviceActionButton.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ const DeviceActionButton = ({
action,
busyActionId,
setBusyActionId,
isDoorOpen,
}) => {
const actionId = deviceId + '/' + action;
const loading = actionId === busyActionId;
Expand Down Expand Up @@ -67,13 +68,21 @@ const DeviceActionButton = ({
}
}

const variant = isDoorOpen ? 'warning' : type.variant;
const icon = isDoorOpen ? 'fa-solid fa-door-open' : type.icon;
const label = t(isDoorOpen ? 'views.door.open' : 'views.devices.' + action);

return (<>
<Button variant={type.variant} className="device-action-button" onClick={handleClick} disabled={disabled}>
<i className={loading ? 'fa-solid fa-arrows-rotate fa-spin' : type.icon} />
<div>{t('views.devices.' + action)}</div>
<Button variant={variant} className="device-action-button" onClick={handleClick} disabled={disabled}>
<i className={loading ? 'fa-solid fa-arrows-rotate fa-spin' : icon} />
<div>{label}</div>
</Button>
{isError && [401, 403].includes(error.status) && <RedirectToLogin />}
</>);
};

DeviceActionButton.defaultProps = {
isDoorOpen: false,
};

export default DeviceActionButton;

0 comments on commit 71677f1

Please sign in to comment.