[WEB-4457] refactor: decouple work item properties from mobx store (#7363)

This commit is contained in:
Prateek Shourya 2025-07-18 20:38:21 +05:30 committed by GitHub
parent 5660b28574
commit f3daac6f95
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
28 changed files with 649 additions and 428 deletions

View file

@ -0,0 +1,27 @@
import { FieldError, FieldValues } from "react-hook-form";
/**
* Get a nested error from a form's errors object
* @param errors - The form's errors object
* @param path - The path to the error
* @returns The error or undefined if not found
*/
export const getNestedError = <T extends FieldValues>(errors: T, path: string): FieldError | undefined => {
const keys = path.split(".");
let current: unknown = errors;
for (const key of keys) {
if (current && typeof current === "object" && key in current) {
current = (current as Record<string, unknown>)[key];
} else {
return undefined;
}
}
// Check if the final value is a FieldError
if (current && typeof current === "object" && "message" in current) {
return current as FieldError;
}
return undefined;
};