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

Add button on no info modal to sync cohorts tasks #1594

Merged
merged 7 commits into from
Sep 24, 2024
Merged
6 changes: 6 additions & 0 deletions public/locales/en/assignments.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@
"no-upload-students": "The following students are still pending to upload their final project information.",
"see-students": "See students",
"no-information": "It is possible that the student never opened this assignment. No information was found about this student assignment",
"sync-cohort": "You can synchronize all the students tasks in the cohort",
"sync": "Synchronize",
"sync-cohort-title": "Synchronize cohort",
"sync-warning": "WARNING: This operation should only be performed on cohorts with serious synchronization problems",
"cancel": "Cancel",
"error-msg": "Something went wrong while synchronizing the cohort",
"educational-status": "Educational Status",
"delivered-percentage": "% delivered",
"last-deliver": "Last delivery: {{date}} ago",
Expand Down
5 changes: 5 additions & 0 deletions public/locales/es/assignments.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@
"no-upload-students": "Los siguientes estudiantes aún están pendientes de subir la información de su proyecto final.",
"see-students": "Ver estudiantes",
"no-information": "Es posible que el estudiante nunca haya abierto esta tarea. No se encontró información sobre la tarea de este estudiante.",
"sync-cohort": "Puedes sincronizar todas las asignaciones de los estudiantes de la cohorte",
"sync": "Sincronizar",
"sync-cohort-title": "Sincronizar la cohorte",
"sync-warning": "ADVERTENCIA: Esta operación solo debe realizarse en cohortes con problemas graves de sincronización.",
"cancel": "Cancelar",
"educational-status": "Estatus eduacional",
"delivered-percentage": "% de entregado",
"last-deliver": "Última entrega: hace {{date}}",
Expand Down
9 changes: 4 additions & 5 deletions src/common/components/ReviewModal/DeliverModalContent.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable react/no-unstable-nested-components */
import { useEffect, useState, useRef } from 'react';
import {
Box,
Expand All @@ -24,7 +23,7 @@ import bc from '../../services/breathecode';
import useStyle from '../../hooks/useStyle';
import Icon from '../Icon';

function DeliverModal({
function DeliverModalContent({
isStudent,
currentTask,
projectLink,
Expand Down Expand Up @@ -215,7 +214,7 @@ function DeliverModal({
);
}

DeliverModal.propTypes = {
DeliverModalContent.propTypes = {
isStudent: PropTypes.bool,
currentTask: PropTypes.objectOf(PropTypes.oneOfType([PropTypes.any])).isRequired,
projectLink: PropTypes.string.isRequired,
Expand All @@ -229,7 +228,7 @@ DeliverModal.propTypes = {
loaders: PropTypes.objectOf(PropTypes.oneOfType([PropTypes.any])),
proceedToCommitFiles: PropTypes.func,
};
DeliverModal.defaultProps = {
DeliverModalContent.defaultProps = {
isStudent: false,
readOnly: false,
showCodeReviews: false,
Expand All @@ -239,4 +238,4 @@ DeliverModal.defaultProps = {
proceedToCommitFiles: () => {},
};

export default DeliverModal;
export default DeliverModalContent;
4 changes: 2 additions & 2 deletions src/common/components/ReviewModal/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ function ReviewModal({ isExternal, externalFiles, isOpen, isStudent, externalDat
const hasNotBeenReviewed = revisionStatus === PENDING;
const hasBeenApproved = revisionStatus === APPROVED;
const hasBeenRejected = revisionStatus === REJECTED;
const noFilesToReview = !hasBeenApproved && contextData?.commitFiles?.fileList?.length === 0;
const noFilesToReview = !hasBeenApproved && (contextData?.commitFiles?.fileList?.length === 0 || !('commitFiles' in contextData));
const codeRevisionsNotExists = typeof contextData?.code_revisions === 'undefined';
const hasFilesToReview = contextData?.code_revisions?.length > 0 || !isStudent; // Used to show rigobot files content
const stage = stageHistory?.current;
Expand Down Expand Up @@ -626,7 +626,7 @@ function ReviewModal({ isExternal, externalFiles, isOpen, isStudent, externalDat
</Box>
</Box>
)}
{(!isAuthenticatedWithRigobot || !noFilesToReview) && hasFilesToReview && !disableRate && (
{(!isAuthenticatedWithRigobot || !noFilesToReview) && hasFilesToReview && !disableRate && contextData?.commitFiles?.fileList?.length > 0 && (
<Flex padding="8px" flexDirection="column" gridGap="16px" background={featuredColor} borderRadius="4px">
<Flex alignItems="center" gridGap="10px">
<Icon icon="code" width="18.5px" height="17px" color="currentColor" />
Expand Down
1 change: 1 addition & 0 deletions src/common/services/breathecode.js
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,7 @@ const breathecode = {
personalFiles: (taskId) => breathecode.get(`${url}/me/task/${taskId}/commitfile${qs}`),
personalFile: (commitId) => breathecode.get(`${url}/me/commitfile/${commitId}${qs}`),
rateCodeRevision: (coderevisionId, data) => axios.post(`${url}/me/coderevision/${coderevisionId}/rate`, data),
syncCohort: (cohortId) => axios.get(`${url}/academy/cohort/${cohortId}/synctasks`),
};
},
feedback: () => {
Expand Down
1 change: 1 addition & 0 deletions src/common/views/StudentAssignments.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ function StudentAssignments({ currentStudentList, updpateAssignment, syllabusDat
<NoInfoModal
isOpen={currentTask && !currentTask.status}
onClose={() => setCurrentTask(null)}
selectedCohort={selectedCohort}
/>
<DeliverModal
currentTask={currentTask}
Expand Down
71 changes: 67 additions & 4 deletions src/js_modules/assignmentHandler/index.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable react/no-unstable-nested-components */
import {
Box, Button, Link, Modal, ModalBody, ModalCloseButton, ModalContent, ModalFooter, ModalHeader, ModalOverlay, Text, useToast, useColorModeValue, useDisclosure,
Box, Button, Link, Modal, ModalBody, ModalCloseButton, ModalContent, ModalFooter, ModalHeader, ModalOverlay, useToast, useColorModeValue, useDisclosure,
} from '@chakra-ui/react';
import useTranslation from 'next-translate/useTranslation';
import { useRouter } from 'next/router';
Expand All @@ -11,6 +11,8 @@ import {
} from 'react';
import bc from '../../common/services/breathecode';
import Icon from '../../common/components/Icon';
import Text from '../../common/components/Text';
import SimpleModal from '../../common/components/SimpleModal';
import useStyle from '../../common/hooks/useStyle';
import { ORIGIN_HOST } from '../../utils/variables';
import ReviewModalComponent from '../../common/components/ReviewModal';
Expand Down Expand Up @@ -204,11 +206,42 @@ function DeliverHandler({
);
}

export function NoInfoModal({ isOpen, onClose }) {
export function NoInfoModal({ isOpen, onClose, selectedCohort }) {
const { t } = useTranslation('assignments');
const toast = useToast();
const [isSyncOpen, setIsSyncOpen] = useState(false);
const { hexColor } = useStyle();
const borderColor2 = useColorModeValue('gray.250', 'gray.500');

const syncCohort = async () => {
try {
const resp = await bc.assignments().syncCohort(selectedCohort.id);
if (resp.status >= 400) throw new Error('Sync error');

const { message } = resp.data;

toast({
position: 'top',
title: 'Success',
description: message,
status: 'success',
duration: 5000,
});
} catch (e) {
console.log(e);
toast({
position: 'top',
title: t('error-msg'),
status: 'error',
duration: 6000,
isClosable: true,
});
} finally {
setIsSyncOpen(false);
onClose();
}
};

return (
<Modal isOpen={isOpen} onClose={onClose} size="lg">
<ModalOverlay />
Expand All @@ -227,8 +260,33 @@ export function NoInfoModal({ isOpen, onClose }) {
</ModalHeader>
<ModalCloseButton />
<ModalBody pb={6} px={{ base: '10px', md: '35px' }}>
<Box display="flex" flexDirection="column" pt={4} pb={5}>
<Text>{t('no-information')}</Text>
<Box display="flex" flexDirection="column" pt={4} pb={5} gap="20px">
<Text size="md">{t('no-information')}</Text>
{selectedCohort && (
<>
<Text size="md" textAlign="center">{t('sync-cohort')}</Text>
<Button variant="default" width="50%" margin="auto" onClick={() => setIsSyncOpen(true)}>
{t('sync')}
</Button>
</>
)}
<SimpleModal
maxWidth="500px"
isOpen={isSyncOpen}
onClose={setIsSyncOpen}
headerStyles={{ textAlign: 'center' }}
title={t('sync-cohort-title')}
>
<Text mt="20px" size="md" textAlign="center">{t('sync-warning')}</Text>
<Box mt="20px" display="flex" gap="15px" width="100%">
<Button fontSize="13px" width="100%" onClick={() => setIsSyncOpen(false)}>
{t('cancel')}
</Button>
<Button variant="default" width="100%" onClick={syncCohort}>
{t('sync')}
</Button>
</Box>
</SimpleModal>
</Box>
</ModalBody>
</ModalContent>
Expand Down Expand Up @@ -393,6 +451,11 @@ ReviewModal.defaultProps = {
NoInfoModal.propTypes = {
isOpen: PropTypes.bool.isRequired,
onClose: PropTypes.func.isRequired,
selectedCohort: PropTypes.objectOf(PropTypes.oneOfType([PropTypes.any])),
};

NoInfoModal.defaultProps = {
selectedCohort: null,
};

DetailsModal.propTypes = {
Expand Down