Skip to content

Commit

Permalink
refactor(client): migrate Bootstrap button in challenge templates (fr…
Browse files Browse the repository at this point in the history
  • Loading branch information
huyenltnguyen authored Jan 5, 2024
1 parent 829e195 commit c93db95
Show file tree
Hide file tree
Showing 29 changed files with 163 additions and 174 deletions.
1 change: 1 addition & 0 deletions client/src/components/helpers/spacer.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React from 'react';

const Padding = Object.freeze({
xxSmall: 2.5,
small: 5,
xSmall: 10,
medium: 15,
Expand Down
4 changes: 0 additions & 4 deletions client/src/components/landing/landing.css
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,6 @@
white-space: pre-line;
}

.cert-btn {
margin-top: 40px;
}

.landing-page ul {
list-style: none;
padding-inline-start: 0;
Expand Down
2 changes: 2 additions & 0 deletions client/src/components/layouts/global.css
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,8 @@ input[type='submit']:hover,
color: var(--secondary-background);
}

button[aria-disabled='true'],
button[aria-disabled='true']:hover,
.btn.disabled,
.btn[disabled],
fieldset[disabled] .btn,
Expand Down
14 changes: 5 additions & 9 deletions client/src/templates/Challenges/classic/lower-jaw.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import React, { useState, useEffect, useRef } from 'react';
import { useTranslation } from 'react-i18next';
import { Button } from '@freecodecamp/react-bootstrap';

import { createSelector } from 'reselect';
import { connect } from 'react-redux';
Expand All @@ -22,8 +21,6 @@ import {
completedPercentageSelector
} from '../redux/selectors';

const lowerJawButtonStyle = 'btn-block btn';

interface LowerJawPanelProps extends ShareProps {
resetButtonText: string;
helpButtonText: string;
Expand Down Expand Up @@ -297,18 +294,17 @@ const LowerJaw = ({
return (
<div className='action-row-container'>
{showSignInButton && (
<Button
<a
data-cy='sign-in-button'
block={true}
href={`${apiLocation}/signin`}
className='btn-cta'
className='btn-cta btn btn-block'
>
{t('learn.sign-in-save')}
</Button>
</a>
)}
<button
data-playwright-test-label='lowerJaw-submit-button'
className={lowerJawButtonStyle}
className='btn-block btn'
data-cy='submit-lowerJaw-button'
onClick={tryToSubmitChallenge}
{...(!challengeIsCompleted && { 'aria-hidden': true })}
Expand All @@ -318,7 +314,7 @@ const LowerJaw = ({
</button>
<button
data-playwright-test-label='lowerJaw-check-button'
className={lowerJawButtonStyle}
className='btn-block btn'
data-cy='check-lowerJaw-button'
onClick={tryToExecuteChallenge}
{...(challengeIsCompleted &&
Expand Down
6 changes: 3 additions & 3 deletions client/src/templates/Challenges/codeally/show.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// Package Utilities
import { Button } from '@freecodecamp/react-bootstrap';
import { graphql } from 'gatsby';
import React, { Component } from 'react';
import Helmet from 'react-helmet';
Expand All @@ -9,7 +8,7 @@ import { connect } from 'react-redux';
import { bindActionCreators } from 'redux';
import type { Dispatch } from 'redux';
import { createSelector } from 'reselect';
import { Container, Col, Row, Alert } from '@freecodecamp/ui';
import { Container, Col, Row, Alert, Button } from '@freecodecamp/ui';

// Local Utilities
import Spacer from '../../../components/helpers/spacer';
Expand Down Expand Up @@ -311,7 +310,7 @@ class ShowCodeAlly extends Component<ShowCodeAllyProps> {
<Button
aria-describedby='codeally-cookie-warning'
block={true}
bsStyle='primary'
variant='primary'
data-cy='start-codeally'
onClick={tryToShowCodeAlly}
>
Expand Down Expand Up @@ -343,6 +342,7 @@ class ShowCodeAlly extends Component<ShowCodeAllyProps> {
/>
</>
)}
<Spacer size='xxSmall' />
<ProjectToolPanel />
<br />
<Spacer size='medium' />
Expand Down
19 changes: 12 additions & 7 deletions client/src/templates/Challenges/components/completion-modal.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
/* eslint-disable @typescript-eslint/restrict-template-expressions */
import { Button, Modal } from '@freecodecamp/react-bootstrap';
import { Modal } from '@freecodecamp/react-bootstrap';
import { noop } from 'lodash-es';
import React, { Component } from 'react';
import type { TFunction } from 'i18next';
import { withTranslation } from 'react-i18next';
import { connect } from 'react-redux';
import { createSelector } from 'reselect';
import { Button } from '@freecodecamp/ui';

import Login from '../../../components/Header/components/login';
import { executeGA } from '../../../redux/actions';
Expand All @@ -26,6 +27,7 @@ import {
} from '../redux/selectors';
import Progress from '../../../components/Progress';
import GreenPass from '../../../assets/icons/green-pass';
import { Spacer } from '../../../components/helpers';

import './completion-modal.css';

Expand Down Expand Up @@ -194,25 +196,28 @@ class CompletionModal extends Component<
</Modal.Body>
<Modal.Footer>
{isSignedIn ? null : (
<Login block={true}>{t('learn.sign-in-save')}</Login>
<>
<Login block={true}>{t('learn.sign-in-save')}</Login>
<Spacer size='xxSmall' />
</>
)}
<Button
block={true}
bsSize='large'
bsStyle='primary'
size='large'
variant='primary'
disabled={isSubmitting}
data-cy='submit-challenge'
onClick={() => submitChallenge()}
>
{isSignedIn ? t('buttons.submit-and-go') : t('buttons.go-to-next')}
<span className='hidden-xs'> (Ctrl + Enter)</span>
</Button>
<Spacer size='xxSmall' />
{this.state.downloadURL ? (
<Button
block={true}
bsSize='lg'
bsStyle='primary'
className='btn-invert'
size='large'
variant='primary'
download={`${dashedName}.txt`}
href={this.state.downloadURL}
>
Expand Down
13 changes: 8 additions & 5 deletions client/src/templates/Challenges/components/help-modal.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
import { faExclamationCircle } from '@fortawesome/free-solid-svg-icons';
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import { Button, Modal } from '@freecodecamp/react-bootstrap';
import { Modal } from '@freecodecamp/react-bootstrap';
import React from 'react';
import { Trans, withTranslation } from 'react-i18next';
import { connect } from 'react-redux';
import { bindActionCreators, Dispatch } from 'redux';
import { Button } from '@freecodecamp/ui';

import envData from '../../../../config/env.json';
import { executeGA } from '../../../redux/actions';
import { createQuestion, closeModal } from '../redux/actions';
import { isHelpModalOpenSelector } from '../redux/selectors';
import { Spacer } from '../../../components/helpers';

import './help-modal.css';

Expand Down Expand Up @@ -93,16 +95,17 @@ function HelpModal({
</div>
<Button
block={true}
bsSize='lg'
bsStyle='primary'
size='large'
variant='primary'
onClick={createQuestion}
>
{t('buttons.create-post')}
</Button>
<Spacer size='xxSmall' />
<Button
block={true}
bsSize='lg'
bsStyle='primary'
size='large'
variant='primary'
onClick={closeHelpModal}
>
{t('buttons.cancel')}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Button, Modal } from '@freecodecamp/react-bootstrap';
import { Modal } from '@freecodecamp/react-bootstrap';
import React, { useEffect } from 'react';
import { connect } from 'react-redux';
import { Button } from '@freecodecamp/ui';

import type { CompletedChallenge } from '../../../redux/prop-types';
import {
Expand Down Expand Up @@ -87,8 +88,8 @@ function ProjectPreviewModal({
<Modal.Footer>
<Button
block={true}
bsSize='lg'
bsStyle='primary'
size='large'
variant='primary'
data-playwright-test-label='project-preview-modal-closeButton'
onClick={() => {
closeModal('projectPreview');
Expand Down
7 changes: 4 additions & 3 deletions client/src/templates/Challenges/components/reset-modal.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
// Package Utilities
import { Button, Modal } from '@freecodecamp/react-bootstrap';
import { Modal } from '@freecodecamp/react-bootstrap';
import React from 'react';
import { useTranslation } from 'react-i18next';
import { connect } from 'react-redux';
import { bindActionCreators, Dispatch } from 'redux';
import { createSelector } from 'reselect';
import { Button } from '@freecodecamp/ui';

// Local Utilities
import { executeGA } from '../../../redux/actions';
Expand Down Expand Up @@ -74,8 +75,8 @@ function ResetModal({ reset, close, isOpen }: ResetModalProps): JSX.Element {
<Button
data-cy='reset-modal-confirm'
block={true}
bsSize='large'
bsStyle='danger'
size='large'
variant='danger'
onClick={withActions(reset, close)}
>
{t('buttons.reset-lesson')}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import React from 'react';
import { Button, Modal } from '@freecodecamp/react-bootstrap';
import { Modal } from '@freecodecamp/react-bootstrap';
import { withTranslation } from 'react-i18next';
import { connect } from 'react-redux';
import { bindActionCreators, Dispatch } from 'redux';
import { createSelector } from 'reselect';
import { Button } from '@freecodecamp/ui';

import { closeModal } from '../redux/actions';
import { isShortcutsModalOpenSelector } from '../redux/selectors';
Expand Down Expand Up @@ -103,8 +104,8 @@ function ShortcutsModal({
/>
<Button
block={true}
bsSize='sm'
bsStyle='primary'
size='small'
variant='primary'
onClick={closeShortcutsModal}
>
{t('buttons.close')}
Expand Down
46 changes: 21 additions & 25 deletions client/src/templates/Challenges/components/tool-panel.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { Button } from '@freecodecamp/react-bootstrap';
import { Dropdown, MenuItem } from '@freecodecamp/ui';
import { Dropdown, MenuItem, Button } from '@freecodecamp/ui';
import { faExternalLinkAlt } from '@fortawesome/free-solid-svg-icons';
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import React from 'react';
Expand All @@ -15,6 +14,7 @@ import { challengeMetaSelector } from '../redux/selectors';

import { saveChallenge } from '../../../redux/actions';
import { isSignedInSelector } from '../../../redux/selectors';
import { Spacer } from '../../../components/helpers';

const mapStateToProps = createSelector(
challengeMetaSelector,
Expand Down Expand Up @@ -74,35 +74,31 @@ function ToolPanel({
isMobile ? 'tool-panel-group-mobile' : ''
}`}
>
<Button
aria-label='Run the tests use shortcut Ctrl+enter'
block={true}
bsStyle='primary'
onClick={handleRunTests}
>
<Button block={true} variant='primary' onClick={handleRunTests}>
{isMobile ? t('buttons.run') : t('buttons.run-test')}
</Button>
{isSignedIn && challengeType === challengeTypes.multifileCertProject && (
<Button
block={true}
bsStyle='primary'
data-cy='save-code-to-database-btn'
className='btn-invert'
onClick={saveChallenge}
>
{isMobile ? t('buttons.save') : t('buttons.save-code')}
</Button>
<>
<Spacer size='xxSmall' />
<Button
block={true}
variant='primary'
data-cy='save-code-to-database-btn'
onClick={saveChallenge}
>
{isMobile ? t('buttons.save') : t('buttons.save-code')}
</Button>
</>
)}
{challengeType !== challengeTypes.multifileCertProject && (
<Button
block={true}
bsStyle='primary'
className='btn-invert'
onClick={openResetModal}
>
{isMobile ? t('buttons.reset') : t('buttons.reset-lesson')}
</Button>
<>
<Spacer size='xxSmall' />
<Button block={true} variant='primary' onClick={openResetModal}>
{isMobile ? t('buttons.reset') : t('buttons.reset-lesson')}
</Button>
</>
)}
<Spacer size='xxSmall' />
<Dropdown dropup>
<Dropdown.Toggle
id={'get-help-dropdown'}
Expand Down
15 changes: 4 additions & 11 deletions client/src/templates/Challenges/dialogue/show.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// Package Utilities
import { Button } from '@freecodecamp/react-bootstrap';
import { graphql } from 'gatsby';
import React, { Component } from 'react';
import Helmet from 'react-helmet';
Expand All @@ -10,7 +9,7 @@ import { connect } from 'react-redux';
import { bindActionCreators } from 'redux';
import type { Dispatch } from 'redux';
import { createSelector } from 'reselect';
import { Container, Col, Row } from '@freecodecamp/ui';
import { Container, Col, Row, Button } from '@freecodecamp/ui';

// Local Utilities
import Spacer from '../../../components/helpers/spacer';
Expand Down Expand Up @@ -273,20 +272,14 @@ class ShowDialogue extends Component<ShowDialogueProps, ShowDialogueState> {
<Spacer size='medium' />
<Button
block={true}
bsSize='large'
bsStyle='primary'
variant='primary'
disabled={!this.state.allAssignmentsCompleted}
onClick={() => this.handleSubmit()}
>
{t('buttons.submit')}
</Button>
<Button
block={true}
bsSize='large'
bsStyle='primary'
className='btn-invert'
onClick={openHelpModal}
>
<Spacer size='xxSmall' />
<Button block={true} variant='primary' onClick={openHelpModal}>
{t('buttons.ask-for-help')}
</Button>
<Spacer size='large' />
Expand Down
Loading

0 comments on commit c93db95

Please sign in to comment.