Skip to content

Commit 871c68e

Browse files
committed
Fix max expiry shown on uploads page
1 parent 938f235 commit 871c68e

File tree

5 files changed

+29
-25
lines changed

5 files changed

+29
-25
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,3 +207,4 @@ $RECYCLE.BIN/
207207
accessgrant.txt
208208
cleanup/backup-*
209209
app/cypress/downloads
210+
cleanup/prod.env

app/src/components/AdvancedControls.jsx

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,21 +18,24 @@ export const validationRules = {
1818
}).safeParse(value).success
1919
}
2020

21-
export function AdvancedControls({ form }) {
21+
export function AdvancedControls({ form, maxDays = null }) {
2222
const [opened, setOpened] = useState(false);
2323

24-
const dates = [1, 7, 30, 60, 90, -1].map((days) => {
25-
if (days === -1) return {
26-
value: days.toString(),
27-
label: "Never"
28-
};
29-
const date = new Date();
30-
date.setDate(date.getDate() + days);
31-
return {
32-
value: days.toString(),
33-
label: `in ${days} day${(days > 1) ? 's' : ''}`
34-
}
35-
})
24+
const dates = [1, 7, 14, 30, 60, 90, -1]
25+
// remove days that are over the maximum if the maximum is set
26+
.filter((days) => maxDays != null ? days <= maxDays && days > 0 : true)
27+
.map((days) => {
28+
if (days === -1) return {
29+
value: days.toString(),
30+
label: "Never"
31+
};
32+
const date = new Date();
33+
date.setDate(date.getDate() + days);
34+
return {
35+
value: days.toString(),
36+
label: `in ${days} day${(days > 1) ? 's' : ''}`
37+
}
38+
});
3639

3740
return (
3841
<>

app/src/components/CreateInfo.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export function CreateInfo({ form, type }) {
88
{type} that
99
{form.values.expireDays == "-1"
1010
? " will never expire"
11-
: ` will expire in ${form.values.expireDays} days`}
11+
: ` will expire in ${form.values.expireDays} day${form.values.expireDays != "1" ? "s" : ""}`}
1212
.
1313
</Text>
1414
)

app/src/components/UploadForm.jsx

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
11
import { useState } from "react";
22
import { upload } from "../controller";
33
import { Dropzone } from '@mantine/dropzone';
4-
import { Alert, Group, Text } from "@mantine/core";
5-
import { Info, Upload } from "react-feather";
6-
import { useForm } from "@mantine/form";
4+
import { Group, Text } from "@mantine/core";
5+
import { Upload } from "react-feather";
6+
import { useForm } from "@mantine/hooks";
77
import { AdvancedControls, initialValues, validationRules } from "./AdvancedControls";
88
import { CreateInfo } from "./CreateInfo";
99

1010
export function UploadForm({ onResponse, onError }) {
1111
const [loading, setLoading] = useState(false);
1212
const form = useForm({
13-
initialValues,
13+
initialValues: {
14+
...initialValues,
15+
expireDays: "30"
16+
},
1417
validationRules
1518
});
1619

@@ -40,9 +43,6 @@ export function UploadForm({ onResponse, onError }) {
4043

4144
return (
4245
<>
43-
<Alert icon={<Info size={32} />} color="blue" mb="sm">
44-
Uploaded files last a maximum of 30 days.
45-
</Alert>
4646
<Dropzone
4747
id="upload-file"
4848
onDrop={onDrop}
@@ -63,7 +63,7 @@ export function UploadForm({ onResponse, onError }) {
6363
</div>
6464
</Group>
6565
</Dropzone>
66-
<AdvancedControls form={form} />
66+
<AdvancedControls form={form} maxDays={30} />
6767
<CreateInfo form={form} type="upload" />
6868
</>
6969
)

app/yarn.lock

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1235,9 +1235,9 @@ callsites@^3.0.0:
12351235
integrity sha512-P8BjAsXvZS+VIDUI11hHCQEv74YT67YUi5JJFNWIqL235sBmjX4+qx9Muvls5ivyNENctx46xQLQ3aTuE7ssaQ==
12361236

12371237
caniuse-lite@^1.0.30001286:
1238-
version "1.0.30001304"
1239-
resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001304.tgz#38af55ed3fc8220cb13e35e6e7309c8c65a05559"
1240-
integrity sha512-bdsfZd6K6ap87AGqSHJP/s1V+U6Z5lyrcbBu3ovbCCf8cSYpwTtGrCBObMpJqwxfTbLW6YTIdbb1jEeTelcpYQ==
1238+
version "1.0.30001469"
1239+
resolved "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001469.tgz"
1240+
integrity sha512-Rcp7221ScNqQPP3W+lVOYDyjdR6dC+neEQCttoNr5bAyz54AboB4iwpnWgyi8P4YUsPybVzT4LgWiBbI3drL4g==
12411241

12421242
chalk@^2.0.0:
12431243
version "2.4.2"

0 commit comments

Comments
 (0)