Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(folder): update the folder title to not be empty #750

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { Suspense } from "react"
import {
Box,
FormControl,
FormErrorMessage,
FormHelperText,
FormLabel,
Icon,
Expand All @@ -17,7 +16,11 @@ import {
Skeleton,
VStack,
} from "@chakra-ui/react"
import { Button, useToast } from "@opengovsg/design-system-react"
import {
Button,
FormErrorMessage,
useToast,
} from "@opengovsg/design-system-react"
import { useAtomValue, useSetAtom } from "jotai"
import { Controller } from "react-hook-form"
import { BiLink } from "react-icons/bi"
Expand Down Expand Up @@ -75,6 +78,7 @@ const SuspendableModalContent = ({
resourceId: Number(folderId),
})
const { register, handleSubmit, watch, control, formState } = useZodForm({
mode: "onChange",
defaultValues: {
title: originalTitle,
permalink: originalPermalink,
Expand Down Expand Up @@ -165,20 +169,20 @@ const SuspendableModalContent = ({
/>
)}
/>
{errors.permalink?.message && (
{errors.permalink?.message ? (
<FormErrorMessage>{errors.permalink.message}</FormErrorMessage>
) : (
<Box
mt="0.5rem"
py="0.5rem"
px="0.75rem"
bg="interaction.support.disabled"
>
<Icon mr="0.5rem" as={BiLink} />
{permalink}
</Box>
)}

<Box
mt="0.5rem"
py="0.5rem"
px="0.75rem"
bg="interaction.support.disabled"
>
<Icon mr="0.5rem" as={BiLink} />
{permalink}
</Box>

<FormHelperText mt="0.5rem" color="base.content.medium">
{MAX_FOLDER_PERMALINK_LENGTH - (permalink || "").length}{" "}
characters left
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ const PageSettings = () => {

<FormControl isRequired isInvalid={!!errors.title}>
<FormLabel
description="By default, this is the title of your your page. Edit this if
description="Edit this if
you want to show a different title on search engines."
>
Page title
Expand Down
11 changes: 3 additions & 8 deletions apps/studio/src/schemas/folder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ export const readFolderSchema = z

export const baseEditFolderSchema = z.object({
resourceId: z.string(),
permalink: z.optional(permalinkSchema),
title: z.optional(z.string()),
permalink: permalinkSchema,
title: z.string().min(1, { message: "Enter a title for this folder" }),
siteId: z.string(),
})

Expand All @@ -45,12 +45,7 @@ export const editFolderSchema = baseEditFolderSchema.superRefine(
if (!permalink && !title) {
ctx.addIssue({
code: z.ZodIssueCode.custom,
path: ["siteId"],
message: "Either permalink or title must be provided.",
})
ctx.addIssue({
code: z.ZodIssueCode.custom,
path: ["title"],
path: ["permalink", "title"],
message: "Either permalink or title must be provided.",
})
}
Expand Down
Loading