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: Add cancel create library button #1182

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
9 changes: 9 additions & 0 deletions src/library-authoring/create-library/CreateLibrary.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -128,4 +128,13 @@ describe('<CreateLibrary />', () => {
expect(getByRole('alert')).toHaveTextContent('{"field":"Error message"}');
});
});

test('cancel creating library navigates to libraries page', async () => {
const { getByRole } = render(<RootWrapper />);

fireEvent.click(getByRole('button', { name: /cancel/i }));
await waitFor(() => {
expect(mockNavigate).toHaveBeenCalledWith('/libraries');
});
});
});
36 changes: 25 additions & 11 deletions src/library-authoring/create-library/CreateLibrary.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ import { useIntl } from '@edx/frontend-platform/i18n';
import {
Container,
Form,
Button,
StatefulButton,
ActionRow,
} from '@openedx/paragon';
import { Formik } from 'formik';
import { useNavigate } from 'react-router-dom';
Expand Down Expand Up @@ -40,6 +42,10 @@ const CreateLibrary = () => {
isLoading: isOrganizationListLoading,
} = useOrganizationListData();

const handleOnClickCancel = () => {
navigate('/libraries');
};

if (data) {
navigate(`/library/${data.id}`);
}
Expand Down Expand Up @@ -114,17 +120,25 @@ const CreateLibrary = () => {
className=""
controlClasses="pb-2"
/>
<StatefulButton
type="submit"
variant="primary"
className="action btn-primary"
state={isLoading ? 'disabled' : 'enabled'}
disabledStates={['disabled']}
labels={{
enabled: intl.formatMessage(messages.createLibraryButton),
disabled: intl.formatMessage(messages.createLibraryButtonPending),
}}
/>
<ActionRow className="justify-content-start">
<Button
variant="outline-primary"
onClick={handleOnClickCancel}
>
{intl.formatMessage(messages.cancelCreateLibraryButton)}
</Button>
<StatefulButton
type="submit"
variant="primary"
className="action btn-primary"
state={isLoading ? 'disabled' : 'enabled'}
disabledStates={['disabled']}
labels={{
enabled: intl.formatMessage(messages.createLibraryButton),
disabled: intl.formatMessage(messages.createLibraryButtonPending),
}}
/>
</ActionRow>
</Form>
)}
</Formik>
Expand Down
5 changes: 5 additions & 0 deletions src/library-authoring/create-library/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,11 @@ const messages = defineMessages({
defaultMessage: 'Creating..',
description: 'Button text while the library is being created.',
},
cancelCreateLibraryButton: {
id: 'course-authoring.library-authoring.create-library.form.create-library.cancel.button',
defaultMessage: 'Cancel',
description: 'Button text to cancel creating a new library.',
},
});

export default messages;
Loading