Skip to content

Commit

Permalink
Update types
Browse files Browse the repository at this point in the history
  • Loading branch information
jackcloudquery committed Oct 7, 2024
1 parent c0bd3dd commit a371b1b
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
4 changes: 2 additions & 2 deletions etc/plugin-config-ui-lib.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -595,8 +595,8 @@ export interface PluginConfig {
export type PluginConfigFormStep = {
children: (IterableStepComponent | React_2.FC<any>)[];
title: string;
submitGuard?: (formValues: any, callApi: ReturnType<typeof useApiCall>['callApi']) => Promise<boolean | {
error: string;
submitGuard?: (formValues: any, teamName: string, callApi: ReturnType<typeof useApiCall>['callApi']) => Promise<boolean | {
errorMessage: string;
}>;
};

Expand Down
9 changes: 5 additions & 4 deletions src/components/form/configUIForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -145,11 +145,12 @@ export function ConfigUIForm({ prepareSubmitValues }: ConfigUIFormProps) {
const thisStep = getValues('_step');

if (config.steps[thisStep]?.submitGuard) {
const result = await config.steps[thisStep]?.submitGuard(getValues(), callApi);
const resultError = typeof result === 'object' && 'error' in result && result.error;
if (result === false || resultError) {
const result = await config.steps[thisStep]?.submitGuard(getValues(), teamName, callApi);
const resultErrorMessage =
typeof result === 'object' && 'errorMessage' in result && result.errorMessage;
if (result === false || resultErrorMessage) {
setError('root', {
message: resultError || 'Validation failed. Please check the form for errors.',
message: resultErrorMessage || 'Validation failed. Please check the form for errors.',
});

return;
Expand Down
3 changes: 2 additions & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,9 @@ export type PluginConfigFormStep = {
title: string;
submitGuard?: (
formValues: any,
teamName: string,
callApi: ReturnType<typeof useApiCall>['callApi'],
) => Promise<boolean | { error: string }>;
) => Promise<boolean | { errorMessage: string }>;
};

/**
Expand Down

0 comments on commit a371b1b

Please sign in to comment.