| 1 |
import { |
| 2 |
playIcon, |
| 3 |
restartIcon, |
| 4 |
toursIcon, |
| 5 |
} from '@help-center/components/tours/icons'; |
| 6 |
import { useGlobalSyncStore } from '@help-center/state/globals-sync'; |
| 7 |
import { useTourStore } from '@help-center/state/tours'; |
| 8 |
import tours from '@help-center/tours/tours'; |
| 9 |
import { __, isRTL } from '@wordpress/i18n'; |
| 10 |
import { chevronLeft, chevronRight, Icon } from '@wordpress/icons'; |
| 11 |
import classNames from 'classnames'; |
| 12 |
|
| 13 |
export const ToursDashboard = ({ onOpen, classes }) => { |
| 14 |
const { startTour } = useTourStore(); |
| 15 |
const { setVisibility } = useGlobalSyncStore(); |
| 16 |
const availableTours = Object.values(tours).filter( |
| 17 |
(tour) => |
| 18 |
tour.settings.startFrom.includes(window.location.href) || |
| 19 |
!tour.settings.startFrom, |
| 20 |
); |
| 21 |
return ( |
| 22 |
<section className={classes} data-test="help-center-tours-section"> |
| 23 |
<button |
| 24 |
data-test="help-center-tours-open-button" |
| 25 |
type="button" |
| 26 |
onClick={onOpen} |
| 27 |
className={classNames( |
| 28 |
'm-0 flex w-full justify-between gap-2 rounded-md border border-gray-200 bg-transparent p-2.5 text-left hover:bg-gray-100 rtl:text-right', |
| 29 |
{ |
| 30 |
'rounded-b-none': availableTours.length > 0, |
| 31 |
}, |
| 32 |
)} |
| 33 |
> |
| 34 |
<Icon |
| 35 |
icon={toursIcon} |
| 36 |
className="rounded-full border-0 bg-design-main fill-design-text p-2" |
| 37 |
size={48} |
| 38 |
/> |
| 39 |
<div className="grow pl-1"> |
| 40 |
<h1 className="m-0 p-0 text-lg font-medium"> |
| 41 |
{__('Tours', 'extendify-local')} |
| 42 |
</h1> |
| 43 |
<p className="m-0 p-0 text-xs text-gray-800"> |
| 44 |
{__('Learn more about your WordPress admin', 'extendify-local')} |
| 45 |
</p> |
| 46 |
</div> |
| 47 |
<div className="flex h-12 grow-0 items-center justify-between"> |
| 48 |
<Icon |
| 49 |
icon={isRTL() ? chevronLeft : chevronRight} |
| 50 |
size={24} |
| 51 |
className="fill-current text-gray-700" |
| 52 |
/> |
| 53 |
</div> |
| 54 |
</button> |
| 55 |
{availableTours.length > 0 && ( |
| 56 |
<button |
| 57 |
data-extendify-tour-id={availableTours[0].id} |
| 58 |
type="button" |
| 59 |
className="text-base m-0 flex w-full items-center justify-between gap-2 rounded-md rounded-t-none border border-t-0 border-gray-200 bg-transparent p-3 px-4 pl-[4.25rem] text-left font-medium text-gray-900 hover:bg-gray-100 rtl:pl-4 rtl:pr-[4.25rem] rtl:text-right" |
| 60 |
onClick={() => { |
| 61 |
setVisibility('minimized'); |
| 62 |
startTour(availableTours[0]); |
| 63 |
}} |
| 64 |
> |
| 65 |
{__('Tour this page', 'extendify-local')} |
| 66 |
<Icon |
| 67 |
icon={playIcon} |
| 68 |
size={16} |
| 69 |
className={isRTL() ? 'rotate-180' : ''} |
| 70 |
/> |
| 71 |
</button> |
| 72 |
)} |
| 73 |
</section> |
| 74 |
); |
| 75 |
}; |
| 76 |
|
| 77 |
export const Tours = () => { |
| 78 |
const { wasCompleted, startTour } = useTourStore(); |
| 79 |
const { setVisibility } = useGlobalSyncStore(); |
| 80 |
return ( |
| 81 |
<section className="p-4"> |
| 82 |
<ul |
| 83 |
className="m-0 flex flex-col gap-2 p-0" |
| 84 |
data-test="help-center-tours-items-list" |
| 85 |
> |
| 86 |
{Object.values(tours).map((tourData) => { |
| 87 |
const { id, title } = tourData; |
| 88 |
return ( |
| 89 |
<li key={id} className="m-0 p-0" data-extendify-tour-id={id}> |
| 90 |
<button |
| 91 |
type="button" |
| 92 |
className="m-0 flex w-full items-center justify-between gap-2 bg-gray-100 px-4 py-3.5 text-sm font-medium text-gray-900 hover:bg-gray-150" |
| 93 |
onClick={() => { |
| 94 |
setVisibility('minimized'); |
| 95 |
startTour(tourData); |
| 96 |
}} |
| 97 |
> |
| 98 |
{title} |
| 99 |
{wasCompleted(id) ? ( |
| 100 |
<Icon |
| 101 |
data-test="restart-tour-icon" |
| 102 |
icon={restartIcon} |
| 103 |
size={16} |
| 104 |
/> |
| 105 |
) : ( |
| 106 |
<Icon |
| 107 |
data-test="play-tour-icon" |
| 108 |
icon={playIcon} |
| 109 |
className={isRTL() ? 'rotate-180' : ''} |
| 110 |
size={16} |
| 111 |
/> |
| 112 |
)} |
| 113 |
</button> |
| 114 |
</li> |
| 115 |
); |
| 116 |
})} |
| 117 |
</ul> |
| 118 |
</section> |
| 119 |
); |
| 120 |
}; |
| 121 |
|
| 122 |
export const routes = [ |
| 123 |
{ |
| 124 |
slug: 'tours', |
| 125 |
title: __('Tours', 'extendify-local'), |
| 126 |
component: Tours, |
| 127 |
}, |
| 128 |
]; |
| 129 |
|