Skip to content

Commit

Permalink
feat: add percentage on project creation
Browse files Browse the repository at this point in the history
  • Loading branch information
flagrede committed Sep 7, 2023
1 parent 57ff309 commit acc7cfc
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import React from 'react';
import { useLocation } from 'react-router-dom';

import SaveFooter from 'web-components/lib/components/fixed-footer/SaveFooter';

import { getProjectCreationPercentage } from 'pages/ProjectCreate/ProjectCreate.utils';

import { useProjectEditContext } from '../../pages/ProjectEdit';
import { EditProjectPageFooter } from './EditProjectPageFooter';

Expand All @@ -25,6 +28,9 @@ const ProjectPageFooter: React.FC<React.PropsWithChildren<Props>> = ({
}) => {
const { isEdit } = useProjectEditContext();
const saveDisabled = !isValid || isSubmitting;
const { pathname } = useLocation();
const currentStep = pathname.substring(pathname.lastIndexOf('/') + 1);
const percentage = getProjectCreationPercentage({ currentStep });

return isEdit ? (
<EditProjectPageFooter
Expand All @@ -40,7 +46,7 @@ const ProjectPageFooter: React.FC<React.PropsWithChildren<Props>> = ({
onNext={props.onNext}
hideProgress={false} // TODO
saveDisabled={saveDisabled}
percentComplete={0} // TODO
percentComplete={percentage}
/>
);
};
Expand Down
11 changes: 11 additions & 0 deletions web-marketplace/src/pages/ProjectCreate/ProjectCreate.constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
export const PROJECT_CREATION_STEPS = [
'basic-info',
'location',
'roles',
'description',
'media',
'metadata',
'review',
];

export const PROJECT_STEPS_COUNT = PROJECT_CREATION_STEPS.length;
19 changes: 19 additions & 0 deletions web-marketplace/src/pages/ProjectCreate/ProjectCreate.utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import {
PROJECT_CREATION_STEPS,
PROJECT_STEPS_COUNT,
} from './ProjectCreate.constants';

type GetProjectCreationPercentageParams = {
currentStep: string;
};

export const getProjectCreationPercentage = ({
currentStep,
}: GetProjectCreationPercentageParams) => {
const currentIndex = PROJECT_CREATION_STEPS.findIndex(
step => step === currentStep,
);
const percentage = ((currentIndex + 1) / PROJECT_STEPS_COUNT) * 100;

return percentage;
};

0 comments on commit acc7cfc

Please sign in to comment.