Skip to content

Commit

Permalink
Merge pull request #1659 from djnunez-aot/update-work-title
Browse files Browse the repository at this point in the history
Add character limit and character counter to work title
  • Loading branch information
djnunez-aot authored Jan 15, 2024
2 parents c748bf9 + 8683275 commit fb26ff2
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions epictrack-web/src/components/work/WorkForm/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import codeService, { Code } from "../../../services/codeService";
import { Work, defaultWork } from "../../../models/work";
import { ListType } from "../../../models/code";
import { Ministry } from "../../../models/ministry";
import { ETFormLabel } from "../../shared";
import { ETFormLabel, ETFormLabelWithCharacterLimit } from "../../shared";
import { Staff } from "../../../models/staff";
import staffService from "../../../services/staffService/staffService";
import dayjs from "dayjs";
Expand Down Expand Up @@ -40,6 +40,7 @@ const schema = yup.object<Work>().shape({
title: yup
.string()
.required("Title is required")
.max(150, "Title should not exceed 150 characters")
.test({
name: "checkDuplicateWork",
exclusive: true,
Expand All @@ -50,7 +51,9 @@ const schema = yup.object<Work>().shape({
value,
parent["id"]
);
return !(validateWorkResult.data as any)["exists"] as boolean;
return validateWorkResult.data
? (!(validateWorkResult.data as any)["exists"] as boolean)
: true;
}
return true;
},
Expand Down Expand Up @@ -123,8 +126,11 @@ export default function WorkForm({ ...props }) {
formState: { errors },
reset,
setValue,
watch,
} = methods;

const title = watch("title");

React.useEffect(() => {
reset(ctx.item ?? defaultWork);
}, [ctx.item]);
Expand Down Expand Up @@ -318,7 +324,12 @@ export default function WorkForm({ ...props }) {
></ControlledSelectV2>
</Grid>
<Grid item xs={12}>
<ETFormLabel required>Title</ETFormLabel>
<ETFormLabelWithCharacterLimit
characterCount={title?.length || 0}
maxCharacterLength={150}
>
Title
</ETFormLabelWithCharacterLimit>
<ControlledTextField
name="title"
fullWidth
Expand Down

0 comments on commit fb26ff2

Please sign in to comment.