* WIP: add a creatore settings form * WIP: updat the controller to use the Creator Settings FOREM * feat: use the creator settings form for the new action * feat: add some default values for the new action * a note about form data * update the initiaize function to set some default values * feat: update the form to use the model data * feat: permit adn use the attributes within creator_settings_form * update the flash error * refactor: require and permit parameters * chore: use booleans, set defaults and validate the form * spec: update all the creator_settings tests * chore: remove comment * refactor: use self * feat: aggregate failures' * chore: remove the logo uploader in the controller * refactor: update error handling * feat: update the wasy the controller handles success and error * chore: remove the resource errors * feat: show flash message on new line * fix: use a redirect so that we can get back to /new * refactor: pass these values through as they seem to be caching whne setting them as default * chore: change default values * spec: update tests * Fix CreatorSettingsForm specs * fix: use a boolean for public * spec: add another test for the success var * fix: radio button labels to correspond + cyress specs * spec: update based on new changes * spec: update the params and the expected output * spec: update the comments and status * feat: no need for the initialize as we use Active Record Attributes * feat: update the tac and coc to be persisted when ticked * fix: amend spec * blank space * Message Co-authored-by: Michael Kohl <me@citizen428.net>
126 lines
3.5 KiB
JavaScript
126 lines
3.5 KiB
JavaScript
import { h, Component } from 'preact';
|
|
import PropTypes from 'prop-types';
|
|
|
|
export class Navigation extends Component {
|
|
/**
|
|
* A function to render the progress stepper within the `Navigation` component.
|
|
* By default, it does not show the stepper for the first slide (the `IntroSlide` component).
|
|
* It builds a list of `<span>` elements corresponding to the slides, and adds an "active"
|
|
* class to any slide that has already been seen or is currently being seen.
|
|
*
|
|
* @returns {String} The HTML markup for the stepper.
|
|
*/
|
|
createStepper() {
|
|
const { currentSlideIndex, slidesCount } = this.props;
|
|
if (currentSlideIndex === 0) {
|
|
return '';
|
|
}
|
|
|
|
const stepsList = [];
|
|
|
|
// We do not show the stepper on the IntroSlide so we start with `i = 1`.
|
|
for (let i = 1; i < slidesCount; i += 1) {
|
|
const active = i <= currentSlideIndex;
|
|
|
|
stepsList.push(<span class={`dot ${active ? 'active' : ''}`} />);
|
|
}
|
|
return (
|
|
<div data-testid="stepper" class="stepper">
|
|
{stepsList}
|
|
</div>
|
|
);
|
|
}
|
|
|
|
/**
|
|
* A function to render the text for the "next-button" within the `Navigation` component.
|
|
* By default, it renders "Continue" for every slide.
|
|
* If the slide can be skipped, it renders "Skip for now".
|
|
* On the final slide, it renders "Finish".
|
|
*
|
|
* @returns {String} The HTML markup for the stepper.
|
|
*/
|
|
buttonText() {
|
|
const { canSkip, currentSlideIndex, slidesCount } = this.props;
|
|
if (slidesCount - 1 === currentSlideIndex) {
|
|
return 'Finish';
|
|
}
|
|
if (canSkip) {
|
|
return 'Skip for now';
|
|
}
|
|
|
|
return 'Continue';
|
|
}
|
|
|
|
render() {
|
|
const { next, prev, hideNext, hidePrev, disabled, canSkip, className } =
|
|
this.props;
|
|
return (
|
|
<nav
|
|
class={`onboarding-navigation${
|
|
className && className.length > 0 ? ` ${className}` : ''
|
|
}`}
|
|
>
|
|
<div
|
|
class={`navigation-content${
|
|
className && className.length > 0 ? ` ${className}` : ''
|
|
}`}
|
|
>
|
|
{!hidePrev && (
|
|
<div class="back-button-container">
|
|
<button
|
|
onClick={prev}
|
|
data-testid="back-button"
|
|
class="back-button"
|
|
type="button"
|
|
aria-label="Back to previous onboarding step"
|
|
>
|
|
<svg
|
|
width="24"
|
|
height="24"
|
|
fill="none"
|
|
class="crayons-icon"
|
|
xmlns="http://www.w3.org/2000/svg"
|
|
>
|
|
<path d="M7.828 11H20v2H7.828l5.364 5.364-1.414 1.414L4 12l7.778-7.778 1.414 1.414L7.828 11z" />
|
|
</svg>
|
|
</button>
|
|
</div>
|
|
)}
|
|
|
|
{this.createStepper()}
|
|
|
|
{!hideNext && (
|
|
<button
|
|
disabled={disabled}
|
|
onClick={next}
|
|
class={`next-button${canSkip ? ' skip-for-now' : ''}`}
|
|
type="button"
|
|
>
|
|
{this.buttonText()}
|
|
</button>
|
|
)}
|
|
</div>
|
|
</nav>
|
|
);
|
|
}
|
|
}
|
|
|
|
Navigation.propTypes = {
|
|
disabled: PropTypes.bool,
|
|
canSkip: PropTypes.bool,
|
|
class: PropTypes.string,
|
|
prev: PropTypes.func.isRequired,
|
|
next: PropTypes.string.isRequired,
|
|
hideNext: PropTypes.bool,
|
|
hidePrev: PropTypes.bool,
|
|
slidesCount: PropTypes.number.isRequired,
|
|
currentSlideIndex: PropTypes.number.isRequired,
|
|
};
|
|
|
|
Navigation.defaultProps = {
|
|
disabled: false,
|
|
canSkip: false,
|
|
hideNext: false,
|
|
hidePrev: false,
|
|
class: '',
|
|
};
|