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

feat(dashboard): Add handleValidationIssues util #6755

Merged
merged 1 commit into from
Oct 25, 2024
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
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`);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Throw this to Sentry.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll do that in my PR, I need this to be merged

}
});
};
Loading