Skip to content

Commit fd68c1f

Browse files
authored
Merge pull request #99 from kleros/feat/file-uploader-message
Feat/file uploader message
2 parents c64890a + 597435f commit fd68c1f

File tree

4 files changed

+56
-10
lines changed

4 files changed

+56
-10
lines changed

web/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@
6666
},
6767
"dependencies": {
6868
"@cyntler/react-doc-viewer": "^1.16.3",
69-
"@kleros/kleros-app": "^2.0.1",
69+
"@kleros/kleros-app": "^2.0.2",
7070
"@kleros/ui-components-library": "^2.19.0",
7171
"@sentry/react": "^7.93.0",
7272
"@sentry/tracing": "^7.93.0",

web/src/pages/NewTransaction/Terms/Deliverable/index.tsx

+19-4
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ import { responsiveSize } from "styles/responsiveSize";
88
import NavigationButtons from "../../NavigationButtons";
99
import TokenTransaction from "../Payment/TokenTransaction";
1010
import Header from "pages/NewTransaction/Header";
11+
import { Roles, useAtlasProvider } from "@kleros/kleros-app";
12+
import { getFileUploaderMsg } from "src/utils";
13+
import useIsDesktop from "hooks/useIsDesktop";
1114

1215
const Container = styled.div`
1316
display: flex;
@@ -32,7 +35,12 @@ const StyledTextArea = styled(Textarea)`
3235

3336
const StyledFileUploader = styled(FileUploader)`
3437
width: 84vw;
35-
margin-bottom: ${responsiveSize(72, 52)};
38+
margin-bottom: ${responsiveSize(130, 72)};
39+
40+
small {
41+
white-space: pre-line;
42+
text-align: start;
43+
}
3644
3745
${landscapeStyle(
3846
() => css`
@@ -54,7 +62,9 @@ const Deliverable: React.FC = () => {
5462
buyerAddress,
5563
setBuyerAddress,
5664
} = useNewTransactionContext();
65+
const { roleRestrictions } = useAtlasProvider();
5766

67+
const isDesktop = useIsDesktop();
5868
const handleWrite = (event: React.ChangeEvent<HTMLInputElement>) => {
5969
setDeliverableText(event.target.value);
6070
};
@@ -67,8 +77,9 @@ const Deliverable: React.FC = () => {
6777
};
6878

6979
const fileFootMessage =
70-
"You can attach additional information as a PDF file. Important: the above description must reference " +
71-
"the relevant parts of the file content.";
80+
"You can attach additional information here. Important: the above description must reference " +
81+
"the relevant parts of the file content.\n" +
82+
(getFileUploaderMsg(Roles.Policy, roleRestrictions) ?? "");
7283

7384
return (
7485
<Container>
@@ -80,7 +91,11 @@ const Deliverable: React.FC = () => {
8091
onChange={handleWrite}
8192
placeholder="eg. I should receive a website created in React with the following specification: x,y,z."
8293
/>
83-
<StyledFileUploader callback={handleAttachFile} variant="info" msg={fileFootMessage} />
94+
<StyledFileUploader
95+
callback={handleAttachFile}
96+
variant={isDesktop ? "info" : undefined}
97+
msg={fileFootMessage}
98+
/>
8499
<NavigationButtons prevRoute="/new-transaction/title" nextRoute="/new-transaction/payment" />
85100
</>
86101
) : (

web/src/utils/index.ts

+31
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,37 @@
1+
import { Roles } from "@kleros/kleros-app";
2+
13
export const isUndefined = (maybeObject: any): maybeObject is undefined => typeof maybeObject === "undefined";
24

35
/**
46
* Checks if a string is empty or contains only whitespace.
57
*/
68
export const isEmpty = (str: string): boolean => str.trim() === "";
9+
10+
type Role = {
11+
name: string;
12+
restriction: {
13+
maxSize: number;
14+
allowedMimeTypes: string[];
15+
};
16+
};
17+
18+
export const getFileUploaderMsg = (role: Roles, roleRestrictions?: Role[]) => {
19+
if (!roleRestrictions) return;
20+
const restrictions = roleRestrictions.find((supportedRoles) => Roles[supportedRoles.name] === role);
21+
22+
if (!restrictions) return;
23+
24+
const typesString = restrictions.restriction.allowedMimeTypes
25+
.map((type) => {
26+
const [prefix, suffix] = type.split("/");
27+
if (!suffix) return prefix ?? null;
28+
29+
return suffix === "*" ? prefix : suffix;
30+
})
31+
.join(", ");
32+
33+
return `Allowed file types: [${typesString}], Max allowed size: ${(
34+
restrictions.restriction.maxSize /
35+
(1024 * 1024)
36+
).toFixed(2)} MB.`;
37+
};

yarn.lock

+5-5
Original file line numberDiff line numberDiff line change
@@ -4474,7 +4474,7 @@ __metadata:
44744474
"@cyntler/react-doc-viewer": "npm:^1.16.3"
44754475
"@graphql-codegen/cli": "npm:^4.0.1"
44764476
"@graphql-codegen/client-preset": "npm:^4.1.0"
4477-
"@kleros/kleros-app": "npm:^2.0.1"
4477+
"@kleros/kleros-app": "npm:^2.0.2"
44784478
"@kleros/ui-components-library": "npm:^2.19.0"
44794479
"@sentry/react": "npm:^7.93.0"
44804480
"@sentry/tracing": "npm:^7.93.0"
@@ -4529,9 +4529,9 @@ __metadata:
45294529
languageName: unknown
45304530
linkType: soft
45314531

4532-
"@kleros/kleros-app@npm:^2.0.1":
4533-
version: 2.0.1
4534-
resolution: "@kleros/kleros-app@npm:2.0.1"
4532+
"@kleros/kleros-app@npm:^2.0.2":
4533+
version: 2.0.2
4534+
resolution: "@kleros/kleros-app@npm:2.0.2"
45354535
dependencies:
45364536
jose: "npm:^5.9.6"
45374537
peerDependencies:
@@ -4542,7 +4542,7 @@ __metadata:
45424542
react-dom: ^18.3.1
45434543
viem: ^2.21.42
45444544
wagmi: ^2.13.0
4545-
checksum: 10/a193e49fe82738eaa7df3b82857fd74a5407e6ed166edeacd2352bbd149a49ea3cfde98f130fe0473f006761260cbf2475bc4fa138ad05650540eec43b9755d1
4545+
checksum: 10/89cf0536fed4bbb887772daa529d7cad209cea0e5105bcd366fe5e4bc7c5c14fca21aa201ba4d848c7e8addd3fc4921ac54e237afe2a5b7224c9cd219f72e08b
45464546
languageName: node
45474547
linkType: hard
45484548

0 commit comments

Comments
 (0)