Skip to content

Commit

Permalink
Merge pull request #1538 from gustavomm19/solution-project-warning
Browse files Browse the repository at this point in the history
Add solution warning to projects
  • Loading branch information
alesanchezr authored Jul 11, 2024
2 parents a51fabb + 59e7765 commit 717a610
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 28 deletions.
4 changes: 3 additions & 1 deletion public/locales/en/syllabus.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,7 @@
},
"reached-the-end-of-the-module": "You have reached the end of the current module \"{{label}}\" but you can start the next module \"{{nextModuleLabel}}\" right away.",
"start-next-module": "Yes, let's start the next module",
"superseded-message": "This lesson belongs to the legacy archive, we recommend reading a more updated version:"
"superseded-message": "This lesson belongs to the legacy archive, we recommend reading a more updated version:",
"solution-message": "This project includes a model solution that you can review if you need additional guidance.",
"open-solution": "Click here to review the model solution"
}
4 changes: 3 additions & 1 deletion public/locales/es/syllabus.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,7 @@
},
"reached-the-end-of-the-module": "Ha llegado al final del módulo actual \"{{label}}\" pero puede iniciar el siguiente módulo \"{{nextModuleLabel}}\" sin problemas.",
"start-next-module": "Sí, comencemos el siguiente módulo.",
"superseded-message": "Esta lección pertenece al archivo de legado, recomendamos leer una versión más actualizada:"
"superseded-message": "Esta lección pertenece al archivo de legado, recomendamos leer una versión más actualizada:",
"solution-message": "Este proyecto tiene una solución modelo que puedes revisar en caso de necesitar orientación adicional.",
"open-solution": "Haz clic aquí para revisar el modelo de solución"
}
11 changes: 11 additions & 0 deletions src/common/context/AuthContext.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,12 @@ const reducer = (state, action) => {
user: action.payload,
};
}
case 'LOADING': {
return {
...state,
isLoading: action.payload,
};
}
default: {
return { ...state };
}
Expand Down Expand Up @@ -209,6 +215,11 @@ function AuthProvider({ children, pageProps }) {
handleSession(null);
});
}
} else {
dispatch({
type: 'LOADING',
payload: false,
});
}

return null;
Expand Down
4 changes: 3 additions & 1 deletion src/common/hooks/useCohortHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@ import axios from 'axios';
import { useToast } from '@chakra-ui/react';
import useTranslation from 'next-translate/useTranslation';
import { useRouter } from 'next/router';
import useAuth from './useAuth';
import { devLog, getStorageItem } from '../../utils';
import useAssignments from '../store/actions/cohortAction';
import bc from '../services/breathecode';
import { BREATHECODE_HOST, DOMAIN_NAME } from '../../utils/variables';

function useCohortHandler() {
const router = useRouter();
const { user } = useAuth();
const { t, lang } = useTranslation('dashboard');
const { setCohortSession, setTaskCohortNull, setSortedAssignments, setUserCapabilities, state } = useAssignments();

Expand Down Expand Up @@ -48,7 +50,7 @@ function useCohortHandler() {
};

const getCohortAssignments = ({
user, setContextState, slug, cohort,
setContextState, slug, cohort,
}) => {
if (user) {
const academyId = cohort.academy.id;
Expand Down
76 changes: 51 additions & 25 deletions src/pages/syllabus/[cohortSlug]/[lesson]/[lessonSlug]/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ import { log } from '../../../../../utils/logging';
function Content() {
const { t, lang } = useTranslation('syllabus');
const BREATHECODE_HOST = modifyEnv({ queryString: 'host', env: process.env.BREATHECODE_HOST });
const { user } = useAuth();
const { user, isLoading } = useAuth();
const { contextState, setContextState } = useModuleMap();
const [currentTask, setCurrentTask] = useState(null);
const { setUserSession } = useSession();
Expand Down Expand Up @@ -155,15 +155,15 @@ function Content() {
cohortSlug,
});
getCohortAssignments({
user, setContextState, cohort,
setContextState, cohort,
});
};

useEffect(() => {
if (user) {
if (!isLoading) {
setCohortAndAssignments();
}
}, [user]);
}, [isLoading]);

useEffect(() => {
if (currentTask && !currentTask.opened_at) {
Expand Down Expand Up @@ -778,27 +778,53 @@ function Content() {
quizSlug={quizSlug}
lessonSlug={lessonSlug}
currentTask={currentTask}
alerMessage={currentData?.superseded_by?.slug && (
<AlertMessage
type="warning"
zIndex={99}
full
borderRadius="8px"
backgroundColor={featuredCard.yellow.featured}
margin="1rem 0"
style={{
width: '100%',
height: 'auto',
}}
>
<Text size="15px" color={fontColor} letterSpacing="0.05em" style={{ margin: '0' }}>
{t('superseded-message')}
{' '}
<Link fontSize="15px" textDecoration="underline" href={`/${lang}/syllabus/${cohortSlug}/${lesson}/${currentData?.superseded_by?.slug}`}>
{currentData?.superseded_by?.title}
</Link>
</Text>
</AlertMessage>
alerMessage={(
<>
{currentData?.solution_url && (
<AlertMessage
type="warning"
zIndex={99}
full
borderRadius="8px"
backgroundColor={featuredCard.yellow.featured}
margin="1rem 0"
style={{
width: '100%',
height: 'auto',
}}
>
<Text size="15px" color={fontColor} letterSpacing="0.05em" style={{ margin: '0' }}>
{t('solution-message')}
{' '}
<Link fontSize="15px" textDecoration="underline" href={currentData?.solution_url} target="_blank">
You can see it here
</Link>
</Text>
</AlertMessage>
)}
{currentData?.superseded_by?.slug && (
<AlertMessage
type="warning"
zIndex={99}
full
borderRadius="8px"
backgroundColor={featuredCard.yellow.featured}
margin="1rem 0"
style={{
width: '100%',
height: 'auto',
}}
>
<Text size="15px" color={fontColor} letterSpacing="0.05em" style={{ margin: '0' }}>
{t('superseded-message')}
{' '}
<Link fontSize="15px" textDecoration="underline" href={`/${lang}/syllabus/${cohortSlug}/${lesson}/${currentData?.superseded_by?.slug}`}>
{currentData?.superseded_by?.title}
</Link>
</Text>
</AlertMessage>
)}
</>
)}
/>
)}
Expand Down

0 comments on commit 717a610

Please sign in to comment.