feat: add a disabled option in repo alert settings

This commit is contained in:
Ravinou 2023-11-10 16:24:58 +01:00
parent 1f519c50fa
commit 10ad738755
No known key found for this signature in database
GPG key ID: EEEE670C40F6A4D7
7 changed files with 38 additions and 21 deletions

View file

@ -6,6 +6,7 @@ import {
IconInfoCircle,
IconChevronDown,
IconChevronUp,
IconBellOff,
} from '@tabler/icons-react';
import timestampConverter from '../../helpers/functions/timestampConverter';
import StorageBar from '../UI/StorageBar/StorageBar';
@ -53,22 +54,33 @@ export default function Repo(props) {
setDisplayDetails(boolean);
};
//Status indicator
const statusIndicator = () => {
return props.status
? classes.statusIndicatorGreen
: classes.statusIndicatorRed;
};
//Alert indicator
const alertIndicator = () => {
if (props.alert === 0) {
return (
<div className={classes.alertIcon}>
<IconBellOff size={16} color='grey' />
</div>
);
}
};
return (
<>
{displayDetails ? (
<>
<div className={classes.RepoOpen}>
<div className={classes.openFlex}>
{props.status ? (
<div
className={classes.statusIndicatorGreen}
></div>
) : (
<div
className={classes.statusIndicatorRed}
></div>
)}
<div className={statusIndicator()} />
<div className={classes.alias}>{props.alias}</div>
{alertIndicator()}
{props.comment && (
<div className={classes.comment}>
<IconInfoCircle size={16} color='grey' />
@ -141,16 +153,9 @@ export default function Repo(props) {
<>
<div className={classes.RepoClose}>
<div className={classes.closeFlex}>
{props.status ? (
<div
className={classes.statusIndicatorGreen}
></div>
) : (
<div
className={classes.statusIndicatorRed}
></div>
)}
<div className={statusIndicator()} />
<div className={classes.alias}>{props.alias}</div>
{alertIndicator()}
{props.comment && (
<div className={classes.comment}>
<IconInfoCircle size={16} color='#637381' />

View file

@ -148,6 +148,15 @@
}
}
/* Alert icon */
.alertIcon {
display: flex;
flex-direction: row;
align-items: center;
margin-left: 10px;
}
/* GENERAL */
.alias {
font-weight: bold;

View file

@ -116,6 +116,7 @@ export default function RepoList() {
alias={repo.alias}
status={repo.status}
lastSave={repo.lastSave}
alert={repo.alert}
repositoryName={repo.repositoryName}
storageSize={repo.storageSize}
storageUsed={repo.storageUsed}

View file

@ -23,6 +23,7 @@ export default function RepoManage(props) {
} = useForm({ mode: 'onChange' });
//List of possible times for alerts
const alertOptions = [
{ value: 0, label: 'Disabled' },
{ value: 3600, label: '1 hour' },
{ value: 21600, label: '6 hours' },
{ value: 43200, label: '12 hours' },
@ -471,7 +472,7 @@ export default function RepoManage(props) {
x.value ===
targetRepo.alert
)
: alertOptions[3]
: alertOptions[4]
}
control={control}
render={({

View file

@ -102,6 +102,7 @@ export default async function handler(req, res) {
for (let index in newRepoList) {
if (
!newRepoList[index].status &&
newRepoList[index].alert !== 0 &&
(!newRepoList[index].lastStatusAlertSend ||
date - newRepoList[index].lastStatusAlertSend > 90000)
) {

View file

@ -19,7 +19,7 @@ export default async function handler(req, res) {
const { alias, sshPublicKey, size, comment, alert, lanCommand } =
req.body;
//We check that we receive data for each variable. Only "comment" and "lanCommand" are optional in the form.
if (!alias || !sshPublicKey || !size || !alert) {
if (!alias || !sshPublicKey || !size || (!alert && alert !== 0)) {
//If a variable is empty.
res.status(422).json({
message: 'Unexpected data',

View file

@ -19,7 +19,7 @@ export default async function handler(req, res) {
const { alias, sshPublicKey, size, comment, alert, lanCommand } =
req.body;
//We check that we receive data for each variable. Only "comment" and "lanCommand" are optional in the form.
if (!alias || !sshPublicKey || !size || !alert) {
if (!alias || !sshPublicKey || !size || (!alert && alert !== 0)) {
//If a variable is empty.
res.status(422).json({
message: 'Unexpected data',