Skip to content

Commit 10ead81

Browse files
authored
Merge pull request #69 from kleros/feat/file-uploader-message
Feat/file uploader message
2 parents 4c472ac + 9e39555 commit 10ead81

File tree

8 files changed

+114
-23
lines changed

8 files changed

+114
-23
lines changed

web/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@
7070
"dependencies": {
7171
"@cyntler/react-doc-viewer": "^1.17.0",
7272
"@kleros/curate-v2-templates": "workspace:^",
73-
"@kleros/kleros-app": "^2.0.1",
73+
"@kleros/kleros-app": "^2.0.2",
7474
"@kleros/ui-components-library": "^2.20.0",
7575
"@sentry/react": "^7.93.0",
7676
"@sentry/tracing": "^7.93.0",

web/src/components/ActionButton/Modal/EvidenceUpload.tsx

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import LabeledInput from "components/LabeledInput";
55
import { responsiveSize } from "styles/responsiveSize";
66
import { errorToast, infoToast, successToast } from "utils/wrapWithToast";
77
import { Roles, useAtlasProvider } from "@kleros/kleros-app";
8+
import { getFileUploaderMsg } from "src/utils";
9+
import useIsDesktop from "hooks/useIsDesktop";
810

911
const Container = styled.div`
1012
width: 100%;
@@ -35,10 +37,14 @@ const StyledLabel = styled.label`
3537

3638
const StyledFileUploader = styled(FileUploader)`
3739
width: 100%;
38-
margin-bottom: ${responsiveSize(52, 32)};
40+
margin-bottom: ${responsiveSize(150, 72)};
3941
path {
4042
fill: ${({ theme }) => theme.primaryBlue};
4143
}
44+
small {
45+
white-space: pre-line;
46+
text-align: start;
47+
}
4248
`;
4349

4450
export type Evidence = {
@@ -57,7 +63,9 @@ const EvidenceUpload: React.FC<IEvidenceUpload> = ({ setEvidence, setIsEvidenceU
5763
const [title, setTitle] = useState("");
5864
const [description, setDescription] = useState("");
5965
const [fileURI, setFileURI] = useState("");
60-
const { uploadFile } = useAtlasProvider();
66+
const { uploadFile, roleRestrictions } = useAtlasProvider();
67+
const isDesktop = useIsDesktop();
68+
6169
useEffect(() => {
6270
setEvidence({
6371
name: title,
@@ -101,8 +109,10 @@ const EvidenceUpload: React.FC<IEvidenceUpload> = ({ setEvidence, setIsEvidenceU
101109
</DescriptionContainer>
102110
<StyledFileUploader
103111
callback={handleFileUpload}
104-
variant="info"
105-
msg="Additionally, you can add an external file in PDF."
112+
variant={isDesktop ? "info" : undefined}
113+
msg={
114+
"Additionally, you can add an external file.\n" + (getFileUploaderMsg(Roles.Evidence, roleRestrictions) ?? "")
115+
}
106116
/>
107117
</Container>
108118
);

web/src/pages/SubmitItem/ItemField/FieldInput/FileInput.tsx

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,29 @@ import { responsiveSize } from "styles/responsiveSize";
66
import { landscapeStyle } from "styles/landscapeStyle";
77
import { Roles, useAtlasProvider } from "@kleros/kleros-app";
88
import { errorToast, infoToast, successToast } from "utils/wrapWithToast";
9+
import { getFileUploaderMsg } from "src/utils";
10+
import useIsDesktop from "hooks/useIsDesktop";
911

1012
const StyledFileUploader = styled(FileUploader)`
1113
width: 84vw;
12-
margin-bottom: ${responsiveSize(52, 32)};
14+
margin-bottom: ${responsiveSize(150, 72)};
1315
path {
1416
fill: ${({ theme }) => theme.primaryBlue};
1517
}
18+
small {
19+
white-space: pre-line;
20+
text-align: start;
21+
}
1622
${landscapeStyle(
1723
() => css`
1824
width: ${responsiveSize(200, 720)};
1925
`
2026
)};
2127
`;
2228
const FileInput: React.FC<IFieldInput> = ({ fieldProp, handleWrite }) => {
23-
const { uploadFile } = useAtlasProvider();
29+
const { uploadFile, roleRestrictions } = useAtlasProvider();
30+
const isDesktop = useIsDesktop();
31+
2432
const handleFileUpload = (file: File) => {
2533
infoToast("Uploading to IPFS...");
2634
uploadFile(file, Roles.CurateItemFile)
@@ -35,7 +43,13 @@ const FileInput: React.FC<IFieldInput> = ({ fieldProp, handleWrite }) => {
3543
});
3644
};
3745

38-
return <StyledFileUploader callback={handleFileUpload} variant="info" msg={fieldProp.description} />;
46+
return (
47+
<StyledFileUploader
48+
callback={handleFileUpload}
49+
variant={isDesktop ? "info" : undefined}
50+
msg={`${fieldProp.description}\n${getFileUploaderMsg(Roles.CurateItemFile, roleRestrictions)}`}
51+
/>
52+
);
3953
};
4054

4155
export default FileInput;

web/src/pages/SubmitItem/ItemField/FieldInput/ImageInput.tsx

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,19 @@ import { responsiveSize } from "styles/responsiveSize";
66
import { landscapeStyle } from "styles/landscapeStyle";
77
import { Roles, useAtlasProvider } from "@kleros/kleros-app";
88
import { errorToast, infoToast, successToast } from "utils/wrapWithToast";
9+
import { getFileUploaderMsg } from "src/utils";
10+
import useIsDesktop from "hooks/useIsDesktop";
911

1012
const StyledFileUploader = styled(FileUploader)`
1113
width: 84vw;
12-
margin-bottom: ${responsiveSize(52, 32)};
14+
margin-bottom: ${responsiveSize(150, 72)};
1315
path {
1416
fill: ${({ theme }) => theme.primaryBlue};
1517
}
18+
small {
19+
white-space: pre-line;
20+
text-align: start;
21+
}
1622
${landscapeStyle(
1723
() => css`
1824
width: ${responsiveSize(200, 720)};
@@ -21,7 +27,9 @@ const StyledFileUploader = styled(FileUploader)`
2127
`;
2228

2329
const ImageInput: React.FC<IFieldInput> = ({ fieldProp, handleWrite }) => {
24-
const { uploadFile } = useAtlasProvider();
30+
const { uploadFile, roleRestrictions } = useAtlasProvider();
31+
const isDesktop = useIsDesktop();
32+
2533
const handleFileUpload = (file: File) => {
2634
infoToast("Uploading to IPFS...");
2735

@@ -38,7 +46,13 @@ const ImageInput: React.FC<IFieldInput> = ({ fieldProp, handleWrite }) => {
3846
.finally();
3947
};
4048

41-
return <StyledFileUploader callback={handleFileUpload} variant="info" msg={fieldProp.description} />;
49+
return (
50+
<StyledFileUploader
51+
callback={handleFileUpload}
52+
variant={isDesktop ? "info" : undefined}
53+
msg={`${fieldProp.description}\n${getFileUploaderMsg(Roles.CurateItemImage, roleRestrictions)}`}
54+
/>
55+
);
4256
};
4357

4458
export default ImageInput;

web/src/pages/SubmitList/ListParameters/LogoUpload.tsx

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import { useSubmitListContext } from "context/SubmitListContext";
99
import { errorToast, infoToast, successToast } from "utils/wrapWithToast";
1010
import ListPreview from "./ListPreview";
1111
import { Roles, useAtlasProvider } from "@kleros/kleros-app";
12+
import { getFileUploaderMsg } from "src/utils";
13+
import useIsDesktop from "hooks/useIsDesktop";
1214

1315
const Container = styled.div`
1416
display: flex;
@@ -26,16 +28,21 @@ const Container = styled.div`
2628

2729
const StyledFileUploader = styled(FileUploader)`
2830
width: 100%;
29-
margin-bottom: ${responsiveSize(52, 32)};
31+
margin-bottom: ${responsiveSize(150, 72)};
3032
path {
3133
fill: ${({ theme }) => theme.primaryBlue};
3234
}
35+
small {
36+
white-space: pre-line;
37+
text-align: start;
38+
}
3339
`;
3440

3541
const LogoUpload: React.FC = () => {
3642
const { listMetadata, setListMetadata, setIsLogoUploading } = useSubmitListContext();
3743

38-
const { uploadFile } = useAtlasProvider();
44+
const { uploadFile, roleRestrictions } = useAtlasProvider();
45+
const isDesktop = useIsDesktop();
3946

4047
const handleFileUpload = (file: File) => {
4148
setIsLogoUploading(true);
@@ -76,8 +83,11 @@ const LogoUpload: React.FC = () => {
7683
<Header text="Logo" />
7784
<StyledFileUploader
7885
callback={handleLoad}
79-
variant="info"
80-
msg="Upload a logo to represent your list. The logo should be a 1:1 aspect ratio image with transparent background, in SVG, or PNG."
86+
variant={isDesktop ? "info" : undefined}
87+
msg={
88+
"Upload a logo to represent your list. The logo should be a 1:1 aspect ratio image with transparent background.\n" +
89+
(getFileUploaderMsg(Roles.Logo, roleRestrictions) ?? "")
90+
}
8191
/>
8292
<ListPreview />
8393
<NavigationButtons prevRoute="/submit-list/description" nextRoute="/submit-list/policy" />

web/src/pages/SubmitList/ListParameters/Policy.tsx

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ import { getIpfsUrl } from "utils/getIpfsUrl";
1010
import { Link } from "react-router-dom";
1111
import { Roles, useAtlasProvider } from "@kleros/kleros-app";
1212
import { errorToast, infoToast, successToast } from "utils/wrapWithToast";
13+
import { getFileUploaderMsg } from "src/utils";
14+
import useIsDesktop from "hooks/useIsDesktop";
1315

1416
const Container = styled.div`
1517
display: flex;
@@ -31,15 +33,21 @@ const StyledLabel = styled.label`
3133

3234
const StyledFileUploader = styled(FileUploader)`
3335
width: 100%;
34-
margin-bottom: ${responsiveSize(52, 32)};
36+
margin-bottom: ${responsiveSize(150, 72)};
3537
path {
3638
fill: ${({ theme }) => theme.primaryBlue};
3739
}
40+
small {
41+
white-space: pre-line;
42+
text-align: start;
43+
}
3844
`;
3945

4046
const Policy: React.FC = () => {
4147
const { listMetadata, setListMetadata, setIsPolicyUploading } = useSubmitListContext();
42-
const { uploadFile } = useAtlasProvider();
48+
const { uploadFile, roleRestrictions } = useAtlasProvider();
49+
const isDesktop = useIsDesktop();
50+
4351
const handleFileUpload = (file: File) => {
4452
setIsPolicyUploading(true);
4553
infoToast("Uploading to IPFS...");
@@ -73,7 +81,11 @@ const Policy: React.FC = () => {
7381
</Link>{" "}
7482
.
7583
</StyledLabel>
76-
<StyledFileUploader callback={handleFileUpload} variant="info" msg="You can add the List Policy file in PDF." />
84+
<StyledFileUploader
85+
callback={handleFileUpload}
86+
variant={isDesktop ? "info" : undefined}
87+
msg={"You can add the List Policy file." + (getFileUploaderMsg(Roles.Policy, roleRestrictions) ?? "")}
88+
/>
7789

7890
<NavigationButtons prevRoute="/submit-list/logo" nextRoute="/submit-list/deposit" />
7991
</Container>

web/src/utils/index.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { Roles } from "@kleros/kleros-app";
2+
13
export const isUndefined = (maybeObject: any): maybeObject is undefined => typeof maybeObject === "undefined";
24
export const capitalize = (str: string) => {
35
return str.charAt(0).toUpperCase() + str.slice(1);
@@ -7,3 +9,32 @@ export const capitalize = (str: string) => {
79
* Checks if a string is empty or contains only whitespace.
810
*/
911
export const isEmpty = (str: string): boolean => str.trim() === "";
12+
13+
type Role = {
14+
name: string;
15+
restriction: {
16+
maxSize: number;
17+
allowedMimeTypes: string[];
18+
};
19+
};
20+
21+
export const getFileUploaderMsg = (role: Roles, roleRestrictions?: Role[]) => {
22+
if (!roleRestrictions) return;
23+
const restrictions = roleRestrictions.find((supportedRoles) => Roles[supportedRoles.name] === role);
24+
25+
if (!restrictions) return;
26+
27+
const typesString = restrictions.restriction.allowedMimeTypes
28+
.map((type) => {
29+
const [prefix, suffix] = type.split("/");
30+
if (!suffix) return prefix ?? null;
31+
32+
return suffix === "*" ? prefix : suffix;
33+
})
34+
.join(", ");
35+
36+
return `Allowed file types: [${typesString}], Max allowed size: ${(
37+
restrictions.restriction.maxSize /
38+
(1024 * 1024)
39+
).toFixed(2)} MB.`;
40+
};

yarn.lock

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4652,7 +4652,7 @@ __metadata:
46524652
"@graphql-codegen/client-preset": "npm:^4.2.0"
46534653
"@kleros/curate-v2-templates": "workspace:^"
46544654
"@kleros/curate-v2-tsconfig": "workspace:^"
4655-
"@kleros/kleros-app": "npm:^2.0.1"
4655+
"@kleros/kleros-app": "npm:^2.0.2"
46564656
"@kleros/kleros-v2-contracts": "npm:^0.3.2"
46574657
"@kleros/ui-components-library": "npm:^2.20.0"
46584658
"@sentry/react": "npm:^7.93.0"
@@ -4711,9 +4711,9 @@ __metadata:
47114711
languageName: unknown
47124712
linkType: soft
47134713

4714-
"@kleros/kleros-app@npm:^2.0.1":
4715-
version: 2.0.1
4716-
resolution: "@kleros/kleros-app@npm:2.0.1"
4714+
"@kleros/kleros-app@npm:^2.0.2":
4715+
version: 2.0.2
4716+
resolution: "@kleros/kleros-app@npm:2.0.2"
47174717
dependencies:
47184718
jose: "npm:^5.9.6"
47194719
peerDependencies:
@@ -4724,7 +4724,7 @@ __metadata:
47244724
react-dom: ^18.3.1
47254725
viem: ^2.21.42
47264726
wagmi: ^2.13.0
4727-
checksum: a193e49fe82738eaa7df3b82857fd74a5407e6ed166edeacd2352bbd149a49ea3cfde98f130fe0473f006761260cbf2475bc4fa138ad05650540eec43b9755d1
4727+
checksum: 89cf0536fed4bbb887772daa529d7cad209cea0e5105bcd366fe5e4bc7c5c14fca21aa201ba4d848c7e8addd3fc4921ac54e237afe2a5b7224c9cd219f72e08b
47284728
languageName: node
47294729
linkType: hard
47304730

0 commit comments

Comments
 (0)