Skip to content

Commit 4ed43ef

Browse files
authored
Merge pull request #1847 from kleros/feat/upload-restrictions-message
feat(web): file-restrictions-message
2 parents 07327fa + 2735f07 commit 4ed43ef

File tree

3 files changed

+51
-11
lines changed

3 files changed

+51
-11
lines changed

web/src/pages/Cases/CaseDetails/Evidence/SubmitEvidenceModal.tsx

+10-4
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@ import styled from "styled-components";
44
import Modal from "react-modal";
55
import { useWalletClient, usePublicClient, useConfig } from "wagmi";
66

7-
import { useAtlasProvider, Roles } from "@kleros/kleros-app";
7+
import { Roles, useAtlasProvider } from "@kleros/kleros-app";
88
import { Textarea, Button, FileUploader } from "@kleros/ui-components-library";
99

1010
import { simulateEvidenceModuleSubmitEvidence } from "hooks/contracts/generated";
1111
import { wrapWithToast, errorToast, infoToast, successToast } from "utils/wrapWithToast";
1212

13-
import { isEmpty } from "src/utils";
13+
import { getFileUploaderMsg, isEmpty } from "src/utils";
1414

1515
import EnsureAuth from "components/EnsureAuth";
1616
import { EnsureChain } from "components/EnsureChain";
@@ -43,6 +43,7 @@ const StyledTextArea = styled(Textarea)`
4343

4444
const StyledFileUploader = styled(FileUploader)`
4545
width: 100%;
46+
margin-bottom: 50px;
4647
`;
4748

4849
const ButtonArea = styled.div`
@@ -62,7 +63,7 @@ const SubmitEvidenceModal: React.FC<{
6263
const [isSending, setIsSending] = useState(false);
6364
const [message, setMessage] = useState("");
6465
const [file, setFile] = useState<File>();
65-
const { uploadFile } = useAtlasProvider();
66+
const { uploadFile, roleRestrictions } = useAtlasProvider();
6667

6768
const isDisabled = useMemo(() => isSending || isEmpty(message), [isSending, message]);
6869

@@ -98,7 +99,11 @@ const SubmitEvidenceModal: React.FC<{
9899
onChange={(e) => setMessage(e.target.value)}
99100
placeholder="Your Arguments"
100101
/>
101-
<StyledFileUploader callback={(file: File) => setFile(file)} />
102+
<StyledFileUploader
103+
callback={(file: File) => setFile(file)}
104+
msg={getFileUploaderMsg(Roles.Evidence, roleRestrictions)}
105+
variant="info"
106+
/>
102107
<ButtonArea>
103108
<Button variant="secondary" disabled={isSending} text="Return" onClick={close} />
104109
<EnsureChain>
@@ -120,6 +125,7 @@ const constructEvidence = async (
120125
if (file) {
121126
infoToast("Uploading to IPFS");
122127
fileURI = await uploadFile(file, Roles.Evidence).catch((err) => {
128+
// eslint-disable-next-line no-console
123129
console.log(err);
124130
errorToast(`Upload failed: ${err?.message}`);
125131
return null;

web/src/pages/Resolver/Policy/index.tsx

+14-7
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,21 @@
11
import React from "react";
22
import styled, { css } from "styled-components";
33

4+
import { useAtlasProvider, Roles } from "@kleros/kleros-app";
45
import { FileUploader } from "@kleros/ui-components-library";
56

6-
import { useAtlasProvider, Roles } from "@kleros/kleros-app";
77
import { useNewDisputeContext } from "context/NewDisputeContext";
8+
import useIsDesktop from "hooks/useIsDesktop";
9+
import { errorToast, infoToast, successToast } from "utils/wrapWithToast";
10+
11+
import { getFileUploaderMsg } from "src/utils";
812

913
import { landscapeStyle } from "styles/landscapeStyle";
1014
import { responsiveSize } from "styles/responsiveSize";
1115

1216
import Header from "pages/Resolver/Header";
1317

1418
import NavigationButtons from "../NavigationButtons";
15-
import { errorToast, infoToast, successToast } from "utils/wrapWithToast";
1619

1720
const Container = styled.div`
1821
display: flex;
@@ -38,19 +41,23 @@ const StyledLabel = styled.label`
3841

3942
const StyledFileUploader = styled(FileUploader)`
4043
width: 84vw;
41-
margin-bottom: ${responsiveSize(52, 32)};
44+
margin-bottom: ${responsiveSize(150, 72)};
4245
4346
${landscapeStyle(
4447
() => css`
4548
width: ${responsiveSize(442, 700, 900)};
4649
`
4750
)}
51+
small {
52+
white-space: pre-line;
53+
text-align: start;
54+
}
4855
`;
4956

5057
const Policy: React.FC = () => {
5158
const { disputeData, setDisputeData, setIsPolicyUploading } = useNewDisputeContext();
52-
const { uploadFile } = useAtlasProvider();
53-
59+
const { uploadFile, roleRestrictions } = useAtlasProvider();
60+
const isDesktop = useIsDesktop();
5461
const handleFileUpload = (file: File) => {
5562
setIsPolicyUploading(true);
5663
infoToast("Uploading Policy to IPFS");
@@ -78,8 +85,8 @@ const Policy: React.FC = () => {
7885
</StyledLabel>
7986
<StyledFileUploader
8087
callback={handleFileUpload}
81-
variant="info"
82-
msg="You can attach additional information as a PDF file. Important: the above description must reference the relevant parts of the file content."
88+
variant={isDesktop ? "info" : undefined}
89+
msg={`You can attach additional information here. Important: the above description must reference the relevant parts of the file content.\n${getFileUploaderMsg(Roles.Policy, roleRestrictions)}`}
8390
/>
8491

8592
<NavigationButtons prevRoute="/resolver/notable-persons" nextRoute="/resolver/preview" />

web/src/utils/index.ts

+27
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { Roles } from "@kleros/kleros-app";
2+
13
import { DEFAULT_CHAIN, getChain } from "consts/chains";
24

35
export const isUndefined = (maybeObject: any): maybeObject is undefined | null =>
@@ -10,3 +12,28 @@ export const isEmpty = (str: string): boolean => str.trim() === "";
1012

1113
export const getTxnExplorerLink = (hash: string) =>
1214
`${getChain(DEFAULT_CHAIN)?.blockExplorers?.default.url}/tx/${hash}`;
15+
16+
type Role = {
17+
name: string;
18+
restriction: {
19+
maxSize: number;
20+
allowedMimeTypes: string[];
21+
};
22+
};
23+
24+
export const getFileUploaderMsg = (role: Roles, roleRestrictions?: Role[]) => {
25+
if (!roleRestrictions) return;
26+
const restrictions = roleRestrictions.find((supportedRoles) => Roles[supportedRoles.name] === role);
27+
28+
if (!restrictions) return;
29+
const typesString = restrictions.restriction.allowedMimeTypes
30+
.map((type) => {
31+
const [prefix, suffix] = type.split("/");
32+
if (!suffix) return prefix ?? null;
33+
34+
return suffix === "*" ? prefix : suffix;
35+
})
36+
.join(", ");
37+
38+
return `Allowed file types: [${typesString}], Max allowed size: ${(restrictions.restriction.maxSize / (1024 * 1024)).toFixed(2)} MB.`;
39+
};

0 commit comments

Comments
 (0)