This repository has been archived by the owner on Jul 23, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #161 from parodos-dev/revert-160-dl/request-access…
…-call Revert "Add request access to a project"
- Loading branch information
Showing
12 changed files
with
109 additions
and
278 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 0 additions & 29 deletions
29
plugins/parodos/src/components/projects/hooks/useRequestAccess.ts
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 26 additions & 8 deletions
34
plugins/parodos/src/components/workflow/hooks/useStartWorkflow.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,55 @@ | ||
import { fetchApiRef, useApi } from '@backstage/core-plugin-api'; | ||
import { IChangeEvent } from '@rjsf/core-v5'; | ||
import { type StrictRJSFSchema } from '@rjsf/utils'; | ||
import { useNavigate } from 'react-router-dom'; | ||
import useAsyncFn, { type AsyncFnReturn } from 'react-use/lib/useAsyncFn'; | ||
import { useExecuteWorkflow } from '../../../hooks/useExecuteWorkflow'; | ||
import { WorkflowDefinition } from '../../../models/workflowDefinitionSchema'; | ||
import { WorkflowStatus } from '../../../models/workflowTaskSchema'; | ||
import { getWorklfowsPayload } from './workflowsPayload'; | ||
|
||
interface UseStartWorkflow { | ||
workflowName: string; | ||
workflowsUrl: string; | ||
workflow: WorkflowDefinition; | ||
projectId: string; | ||
isNew: boolean; | ||
} | ||
|
||
export function useStartWorkflow({ | ||
workflowName, | ||
workflowsUrl, | ||
workflow, | ||
projectId, | ||
isNew, | ||
}: UseStartWorkflow): AsyncFnReturn<(e?: IChangeEvent) => Promise<void>> { | ||
const { fetch } = useApi(fetchApiRef); | ||
const navigate = useNavigate(); | ||
const executeWorkflow = useExecuteWorkflow(workflowName); | ||
|
||
return useAsyncFn( | ||
async ({ formData = {} } = {} as IChangeEvent<StrictRJSFSchema>) => { | ||
const { workFlowExecutionId } = await executeWorkflow({ | ||
const payload = getWorklfowsPayload({ | ||
projectId, | ||
formData, | ||
workflow, | ||
schema: formData, | ||
}); | ||
|
||
const data = await fetch(workflowsUrl, { | ||
method: 'POST', | ||
body: JSON.stringify(payload), | ||
}); | ||
|
||
if (!data.ok) { | ||
throw new Error(`${data.status} - ${data.statusText}`); | ||
} | ||
|
||
const response = (await data.json()) as WorkflowStatus; | ||
const executionId = response.workFlowExecutionId; | ||
|
||
navigate( | ||
`/parodos/onboarding/${projectId}/${workFlowExecutionId}/workflow-detail`, | ||
`/parodos/onboarding/${projectId}/${executionId}/workflow-detail`, | ||
{ | ||
state: { isNew }, | ||
}, | ||
); | ||
}, | ||
[projectId, navigate, isNew, executeWorkflow], | ||
[projectId, workflow, fetch, workflowsUrl, navigate, isNew], | ||
); | ||
} |
Oops, something went wrong.