Skip to content

Commit

Permalink
feat(dashboard): Add handleValidationIssues util (#6755)
Browse files Browse the repository at this point in the history
  • Loading branch information
desiprisg authored Oct 25, 2024
1 parent 692cdda commit f94184f
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
2 changes: 1 addition & 1 deletion apps/dashboard/src/hooks/use-tags-query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { getV2 } from '@/api/api.client';
export const useTagsQuery = () => {
const { currentEnvironment } = useEnvironment();
const query = useQuery<{ data: { name: string }[] }>({
queryKey: [QueryKeys.fetchWorkflow, currentEnvironment?._id],
queryKey: [QueryKeys.fetchTags, currentEnvironment?._id],
queryFn: async () => await getV2(`/environments/${currentEnvironment!._id}/tags`),
enabled: !!currentEnvironment?._id,
});
Expand Down
27 changes: 27 additions & 0 deletions apps/dashboard/src/utils/handleValidationIssues.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { FieldValues, UseFormSetError } from 'react-hook-form';

type ValidationIssues = Record<
string,
{
issueType: string;
message: string;
variableName: string;
}[]
>;

type HandleValidationIssuesProps<T extends FieldValues> = {
fields: T;
issues: ValidationIssues;
setError: UseFormSetError<T>;
};
export const handleValidationIssues = <T extends FieldValues>(props: HandleValidationIssuesProps<T>) => {
const { fields, issues, setError } = props;

(Object.keys(issues) as Array<keyof typeof issues>).map((issueKey) => {
if (issueKey in fields) {
setError(issueKey as any, { message: issues[issueKey][0]?.message || 'Unknown error' });
} else {
console.log(`Issue for ${issueKey} found and does not correspond to a field`);
}
});
};

0 comments on commit f94184f

Please sign in to comment.