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

♻️ small refactor #1766

Open
wants to merge 2 commits into
base: development
Choose a base branch
from
Open
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: 5 additions & 4 deletions src/common/components/Module.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@ import Text from './Text';
import Icon from './Icon';
// import Link from './NextChakraLink';
import ModalInfo from '../../js_modules/moduleMap/modalInfo';
import { addQueryToURL } from '../../utils';

function Module({
onClickHandler, data, containerStyle, leftContentStyle, containerPX, width, currIndex,
isDone, rightItemHandler, link, textWithLink, mandatory, onDisabledClick,
}) {
const { t } = useTranslation('dashboard');
const { t, lang } = useTranslation('dashboard');
const containerBackground = isDone ? useColorModeValue('featuredLight', 'featuredDark') : useColorModeValue('white', 'primary');
const commonFontColor = useColorModeValue('gray.600', 'gray.200');
const [openModal, setOpenModal] = useState(false);
Expand Down Expand Up @@ -49,7 +50,7 @@ function Module({
title={t('modules.target-blank-title')}
isReadonly
description={t('modules.target-blank-msg', { title: data.title })}
link={data.url}
link={addQueryToURL(data.url, { lang })}
handlerText={t('common:open')}
closeText={t('common:close')}
closeButtonVariant="outline"
Expand Down Expand Up @@ -212,7 +213,7 @@ Module.propTypes = {
onDisabledClick: PropTypes.func,
};
Module.defaultProps = {
onClickHandler: () => {},
onClickHandler: () => { },
data: {},
containerStyle: {},
leftContentStyle: {},
Expand All @@ -224,7 +225,7 @@ Module.defaultProps = {
isDone: false,
currIndex: null,
mandatory: false,
onDisabledClick: () => {},
onDisabledClick: () => { },
};

export default Module;
5 changes: 3 additions & 2 deletions src/js_modules/syllabus/ProjectInstructions.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import Heading from '../../common/components/Heading';
import ModalToCloneProject from './ModalToCloneProject';
import Text from '../../common/components/Text';
import Icon from '../../common/components/Icon';
import { addQueryToURL } from '../../utils';

function ProvisioningPopover({ openInLearnpackAction, provisioningLinks }) {
return (
Expand Down Expand Up @@ -66,7 +67,7 @@ function ProvisioningPopover({ openInLearnpackAction, provisioningLinks }) {
}

function ButtonsHandler({ currentAsset, setShowCloneModal, vendors, handleStartLearnpack, isForOpenLocaly, startWithLearnpack, variant }) {
const { t } = useTranslation('common');
const { t, lang } = useTranslation('common');
const { state } = useCohortHandler();
const { cohortSession } = state;
const openInLearnpackAction = t('learnpack.open-in-learnpack-button', {}, { returnObjects: true });
Expand Down Expand Up @@ -94,7 +95,7 @@ function ButtonsHandler({ currentAsset, setShowCloneModal, vendors, handleStartL

if (isExternalExercise) {
return (
<Button cursor="pointer" as="a" href={currentAsset.url} target="_blank" size="sm" padding="4px 8px" fontSize="14px" fontWeight="500" background="gray.200" color="blue.default">
<Button cursor="pointer" as="a" href={addQueryToURL(currentAsset.url, { lang })} target="_blank" size="sm" padding="4px 8px" fontSize="14px" fontWeight="500" background="gray.200" color="blue.default">
{t('common:learnpack.start-exercise')}
</Button>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
import useTranslation from 'next-translate/useTranslation';
import { useRouter } from 'next/router';
import Head from 'next/head';
import { isWindow, assetTypeValues, getExtensionName, getStorageItem, languageFix } from '../../../../../utils';
import { isWindow, assetTypeValues, getExtensionName, getStorageItem, languageFix, addQueryToURL } from '../../../../../utils';
import asPrivate from '../../../../../common/context/PrivateRouteWrapper';
import Heading from '../../../../../common/components/Heading';
import useModuleHandler from '../../../../../common/hooks/useModuleHandler';
Expand Down Expand Up @@ -420,7 +420,6 @@ function SyllabusContent() {

if (currTask?.target === 'blank') {
setCurrentAsset(data);
return;
}

setReadmeUrlPathname(finalPathname);
Expand Down Expand Up @@ -1462,7 +1461,7 @@ function SyllabusContent() {
title={t('dashboard:modules.target-blank-title')}
isReadonly
description={t('dashboard:modules.target-blank-msg', { title: clickedPage?.title || currentBlankProps?.title })}
link={inputModalLink}
link={addQueryToURL(inputModalLink, { lang })}
handlerText={t('common:open')}
closeText={t('common:close')}
closeButtonVariant="outline"
Expand Down
11 changes: 10 additions & 1 deletion src/utils/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/* eslint-disable indent */
import { addDays, format, isAfter } from 'date-fns';
import { es } from 'date-fns/locale';
import { parseQuerys } from './url';

const isWindow = typeof window !== 'undefined';

Expand Down Expand Up @@ -294,6 +295,14 @@ const getQueryString = (key, def) => {
return urlParams && (urlParams.get(key) || def);
};

const addQueryToURL = (url, params = {}) => {
const urlObj = new URL(url, window.location.origin);
const querys = parseQuerys(params);

if (Array.from(urlObj.searchParams).length > 0) return `${url}&${querys.slice(1)}`;
return `${url}${querys}`;
};

const createArray = (length) => Array.from({ length }, (_, i) => i);
const lengthOfString = (string) => (typeof string === 'string' ? string?.replaceAll(/\s/g, '').length : 0);

Expand Down Expand Up @@ -431,5 +440,5 @@ export {
sortToNearestTodayDate, isNumber, isDateMoreThanAnyDaysAgo, getQueryString, isValidDate,
createArray, url, lengthOfString, syncInterval, getBrowserSize, calculateDifferenceDays, intervalToHours, capitalizeFirstLetter,
adjustNumberBeetwenMinMax, getDiscountedPrice, formatPrice, cleanObject, slugToTitle, decodeBase64,
removeSessionStorageItem, languageFix,
removeSessionStorageItem, languageFix, addQueryToURL,
};