added copyjob pre-requsite screen along with it's validations

This commit is contained in:
Bikram Choudhury
2025-10-21 18:53:02 +05:30
parent a23a7791d4
commit c504d97f7c
21 changed files with 626 additions and 304 deletions

View File

@@ -1,7 +1,8 @@
import { submitCreateCopyJob } from "Explorer/ContainerCopy/Actions/CopyJobActions";
import { useCallback, useMemo, useReducer } from "react";
import { useSidePanel } from "../../../../hooks/useSidePanel";
import { submitCreateCopyJob } from "../../Actions/CopyJobActions";
import { CopyJobContextState } from "../../Types";
import { useCopyJobPrerequisitesCache } from "./useCopyJobPrerequisitesCache";
import { SCREEN_KEYS, useCreateCopyJobScreensList } from "./useCreateCopyJobScreensList";
type NavigationState = {
@@ -34,14 +35,18 @@ function navigationReducer(state: NavigationState, action: Action): NavigationSt
export function useCopyJobNavigation(copyJobState: CopyJobContextState) {
const screens = useCreateCopyJobScreensList();
const { validationCache: cache } = useCopyJobPrerequisitesCache();
const [state, dispatch] = useReducer(navigationReducer, { screenHistory: [SCREEN_KEYS.SelectAccount] });
const currentScreenKey = state.screenHistory[state.screenHistory.length - 1];
const currentScreen = screens.find((screen) => screen.key === currentScreenKey);
const isPrimaryDisabled = useMemo(
() => !currentScreen?.validations.every((v) => v.validate(copyJobState)),
[currentScreen.key, copyJobState]
() => {
const context = currentScreenKey === SCREEN_KEYS.AssignPermissions ? cache : copyJobState;
return !currentScreen?.validations.every((v) => v.validate(context));
},
[currentScreen.key, copyJobState, cache]
);
const primaryBtnText = useMemo(() => {
if (currentScreenKey === SCREEN_KEYS.PreviewCopyJob) {
@@ -53,13 +58,16 @@ export function useCopyJobNavigation(copyJobState: CopyJobContextState) {
const isPreviousDisabled = state.screenHistory.length <= 1;
const handlePrimary = useCallback(() => {
if (currentScreenKey === SCREEN_KEYS.SelectAccount) {
dispatch({ type: "NEXT", nextScreen: SCREEN_KEYS.SelectSourceAndTargetContainers });
}
if (currentScreenKey === SCREEN_KEYS.SelectSourceAndTargetContainers) {
dispatch({ type: "NEXT", nextScreen: SCREEN_KEYS.PreviewCopyJob });
}
if (currentScreenKey === SCREEN_KEYS.PreviewCopyJob) {
const transitions = {
[SCREEN_KEYS.SelectAccount]: SCREEN_KEYS.AssignPermissions,
[SCREEN_KEYS.AssignPermissions]: SCREEN_KEYS.SelectSourceAndTargetContainers,
[SCREEN_KEYS.SelectSourceAndTargetContainers]: SCREEN_KEYS.PreviewCopyJob,
};
const nextScreen = transitions[currentScreenKey];
if (nextScreen) {
dispatch({ type: "NEXT", nextScreen });
} else if (currentScreenKey === SCREEN_KEYS.PreviewCopyJob) {
submitCreateCopyJob(copyJobState);
}
}, [currentScreenKey, copyJobState]);