Skip to content

Commit a003aed

Browse files
authored
Merge pull request #188 from Vizzuality/fix/dashboard-messages-improvements
new regex URL
2 parents 79256b5 + efb85e9 commit a003aed

File tree

12 files changed

+40
-38
lines changed

12 files changed

+40
-38
lines changed

client/src/components/forms/dataset/data-form-schema.tsx

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { z } from "zod";
22

33
import type { VALUE_TYPE } from "./types";
4+
import { URL_REGEX } from "@/lib/utils/url-validator";
45

56
export const getFormSchema = (value_type: VALUE_TYPE, countries: string[]) => {
67
if (value_type === "number") {
@@ -21,21 +22,16 @@ export const getFormSchema = (value_type: VALUE_TYPE, countries: string[]) => {
2122
acc[`${country}`] = z
2223
.array(
2324
z.object({
24-
link_title: z.string().min(1, { message: "Please enter a title" }),
25+
link_title: z.string().min(1, { message: "title" }),
2526
link_url: z
2627
.string()
27-
.regex(
28-
new RegExp(
29-
"^(?=(https?://|www.))((https?://)?(www.)?)[a-zA-Z0-9.-]+.[a-zA-Z]{2,}(/[^s]*)?$",
30-
),
31-
{
32-
message: "Please, enter a valid URL.",
33-
},
34-
)
28+
.regex(new RegExp(URL_REGEX), {
29+
message: "URL",
30+
})
3531
.max(255, {
3632
message: "Website is limited to 255 characters.",
3733
}),
38-
description: z.string().min(1, { message: "Please enter a description" }),
34+
description: z.string().min(1, { message: "description" }),
3935
}),
4036
)
4137
.optional();

client/src/components/map/legend/item/toolbar/index.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { LuEye, LuEyeOff, LuDroplet, LuInfo, LuX } from "react-icons/lu";
66
import { cn } from "@/lib/classnames";
77

88
import { LegendItemToolbarProps } from "@/components/map/legend/types";
9-
import { Dialog, DialogContent, DialogTrigger } from "@/components/ui/dialog";
9+
import { Dialog, DialogContent, DialogTrigger, DialogTitle } from "@/components/ui/dialog";
1010
import { Popover, PopoverContent, PopoverTrigger } from "@/components/ui/popover";
1111
import { Tooltip, TooltipArrow, TooltipContent, TooltipTrigger } from "@/components/ui/tooltip";
1212

@@ -129,6 +129,7 @@ export const LegendItemToolbar: React.FC<LegendItemToolbarProps> = ({
129129
</TooltipContent>
130130

131131
<DialogContent onCloseAutoFocus={(e) => e.preventDefault()}>
132+
<DialogTitle className="sr-only">Info</DialogTitle>
132133
{InfoContent}
133134
</DialogContent>
134135
</Tooltip>

client/src/components/new-dataset/step-description/csv-import.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { LuInfo } from "react-icons/lu";
88

99
import { useRouter } from "next/navigation";
1010

11-
import { Dialog, DialogTrigger, DialogContent } from "@/components/ui/dialog";
11+
import { Dialog, DialogTrigger, DialogContent, DialogTitle } from "@/components/ui/dialog";
1212

1313
import { downloadCSV } from "@/lib/utils/csv";
1414
import { UsersPermissionsRole, UsersPermissionsUser } from "@/types/generated/strapi.schemas";
@@ -150,6 +150,7 @@ export default function CSVImport({
150150
</DialogTrigger>
151151

152152
<DialogContent>
153+
<DialogTitle className="sr-only">Data</DialogTitle>
153154
<CSVInfoContent valueType={valueType} />
154155
</DialogContent>
155156
</Dialog>

client/src/components/ui/form.tsx

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,9 +172,16 @@ const FormMessageArray = React.forwardRef<
172172

173173
if (!e) return children;
174174

175-
return getKeys(e)
175+
const messages = getKeys(e)
176176
.map((k) => e[k]?.message)
177-
.join(", ");
177+
.filter(Boolean);
178+
179+
if (messages.length === 1) return `Please fix the following field: ${messages[0]}.`;
180+
if (messages.length > 1) {
181+
const last = messages.pop();
182+
return `Please fix the following fields: ${messages.join(", ")} and ${last}.`;
183+
}
184+
return children;
178185
}
179186

180187
return error ? String(error?.message) : children;

client/src/containers/collaborators/form/index.tsx

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ import {
5151

5252
import { updateOrCreateCollaborator } from "@/services/collaborators";
5353
import { uploadImage } from "@/services/datasets";
54+
import { URL_REGEX } from "@/lib/utils/url-validator";
5455

5556
const relationshipOptions = [
5657
{
@@ -191,14 +192,9 @@ export default function CollaboratorForm() {
191192
}),
192193
link: z
193194
.string()
194-
.regex(
195-
new RegExp(
196-
"^(?=(https?://|www.))((https?://)?(www.)?)[a-zA-Z0-9.-]+.[a-zA-Z]{2,}(/[^s]*)?$",
197-
),
198-
{
199-
message: "Please, enter a valid URL.",
200-
},
201-
)
195+
.regex(new RegExp(URL_REGEX), {
196+
message: "Please, enter a valid URL.",
197+
})
202198
.max(255, {
203199
message: "Website is limited to 255 characters.",
204200
}),

client/src/containers/countries/countries-detail.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import CountryDownloadDialog from "@/containers/countries/download-dialog";
1212
import { MultiCombobox } from "@/containers/countries/multicombobox";
1313

1414
import { Button } from "@/components/ui/button";
15-
import { Dialog, DialogContent, DialogTrigger } from "@/components/ui/dialog";
15+
import { Dialog, DialogContent, DialogTrigger, DialogTitle } from "@/components/ui/dialog";
1616

1717
import CountriesTable from "./countries-table";
1818

@@ -66,6 +66,7 @@ const CountryDetail = ({ embed }: { embed?: boolean }) => {
6666
<Button variant="primary-outline">Open Table detail</Button>
6767
</DialogTrigger>
6868
<DialogContent className="block max-w-[90svw] md:w-auto">
69+
<DialogTitle className="sr-only">Country data</DialogTitle>
6970
<CountryDataDialog />
7071
</DialogContent>
7172
</Dialog>

client/src/containers/datasets/item.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { DatasetListResponseDataItem } from "@/types/generated/strapi.schemas";
99

1010
import { datasetSearchAtom, useSyncDatasets, useSyncLayers } from "@/app/store";
1111

12-
import { Dialog, DialogContent, DialogTrigger } from "@/components/ui/dialog";
12+
import { Dialog, DialogContent, DialogTrigger, DialogTitle } from "@/components/ui/dialog";
1313
import { ScrollArea } from "@/components/ui/scroll-area";
1414
import SearchHighlight from "@/components/ui/search-highlight";
1515
import { Switch } from "@/components/ui/switch";
@@ -82,6 +82,7 @@ const DatasetsItem = ({ id, attributes }: DatasetListResponseDataItem) => {
8282
</DialogTrigger>
8383

8484
<DialogContent>
85+
<DialogTitle className="sr-only">Dataset</DialogTitle>
8586
<ScrollArea className="max-h-[80svh] p-6">
8687
<Markdown className="prose">{attributes?.description}</Markdown>
8788
</ScrollArea>

client/src/containers/other-tools/form/index.tsx

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ import {
5050
} from "@/components/ui/select";
5151

5252
import { updateOrCreateOtherTools } from "@/services/other-tools";
53+
import { URL_REGEX } from "@/lib/utils/url-validator";
5354

5455
export default function ToolForm() {
5556
const { push, back } = useRouter();
@@ -175,14 +176,9 @@ export default function ToolForm() {
175176
name: z.string().min(1, { message: "Please enter tool name" }),
176177
link: z
177178
.string()
178-
.regex(
179-
new RegExp(
180-
"^(?=(https?://|www.))((https?://)?(www.)?)[a-zA-Z0-9.-]+.[a-zA-Z]{2,}(/[^s]*)?$",
181-
),
182-
{
183-
message: "Please, enter a valid URL.",
184-
},
185-
)
179+
.regex(new RegExp(URL_REGEX), {
180+
message: "Please, enter a valid URL.",
181+
})
186182
.max(255, {
187183
message: "Website is limited to 255 characters.",
188184
}),

client/src/containers/projects/filters/dialog.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import { GET_PILLARS_OPTIONS } from "@/constants/pillars";
1818

1919
import { Button } from "@/components/ui/button";
2020
import { Checkbox } from "@/components/ui/checkbox";
21-
import { Dialog, DialogContent, DialogTrigger } from "@/components/ui/dialog";
21+
import { Dialog, DialogContent, DialogTrigger, DialogTitle } from "@/components/ui/dialog";
2222
import {
2323
Form,
2424
FormControl,
@@ -90,6 +90,7 @@ const ProjectsFiltersDialog = () => {
9090
</DialogTrigger>
9191

9292
<DialogContent>
93+
<DialogTitle className="sr-only">Filters</DialogTitle>
9394
<div className="space-y-5 p-5">
9495
<h2 className="font-metropolis text-3xl tracking-tight">Filters</h2>
9596

client/src/containers/welcome-message/index.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@ import { cn } from "@/lib/classnames";
1414
import { useGetWelcomeMessage } from "@/types/generated/welcome-message";
1515

1616
import { Button } from "@/components/ui/button";
17-
import { Dialog, DialogContent } from "@/components/ui/dialog";
18-
import isEmpty from "lodash-es/isEmpty";
17+
import { Dialog, DialogContent, DialogTitle } from "@/components/ui/dialog";
1918

2019
export default function WelcomeMessage() {
2120
const videoRef = useRef<ReactPlayer>(null);
@@ -41,7 +40,7 @@ export default function WelcomeMessage() {
4140
const handleFullscreen = () => {
4241
setFullscreen(screenfull?.isFullscreen);
4342
};
44-
43+
4544
useEffect(() => {
4645
if (screenfull.isEnabled) {
4746
screenfull.on("change", handleFullscreen);
@@ -57,6 +56,7 @@ export default function WelcomeMessage() {
5756
return (
5857
<Dialog open={!cookies.welcome}>
5958
<DialogContent close={false} className="overflow-hidden border-none lg:max-w-[900px]">
59+
<DialogTitle className="sr-only">Welcome message</DialogTitle>
6060
<div className="flex w-full flex-col overflow-hidden lg:flex-row">
6161
<div className="flex w-full flex-col items-center justify-center space-y-5 p-5 text-center lg:w-1/2 lg:space-y-10 lg:p-12">
6262
<header className="max-w-md space-y-2 lg:space-y-5">

0 commit comments

Comments
 (0)