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

Com 3853 #693

Merged
merged 7 commits into from
Dec 16, 2024
Merged
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
31 changes: 31 additions & 0 deletions src/components/learnerPendingActions/AttendanceSheetCell/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { Text, View, TouchableOpacity } from 'react-native';
import { Feather } from '@expo/vector-icons';
import CompaniDate from '../../../core/helpers/dates/companiDates';
import { AttendanceSheetType } from '../../../types/AttendanceSheetTypes';
import Shadow from '../../design/Shadow';
import { DD_MM_YYYY } from '../../../core/data/constants';
import { ICON } from '../../../styles/metrics';
import { GREY } from '../../../styles/colors';
import styles from './styles';

interface AttendanceSheetCellProps {
attendanceSheet: AttendanceSheetType,
}

const AttendanceSheetCell = ({ attendanceSheet }: AttendanceSheetCellProps) => (
<View style={styles.container}>
<TouchableOpacity style={styles.iconContainer}>
<View style={styles.icon}>
<Feather name='pen-tool' size={ICON.LG} color={GREY[700]} />
</View>
<Shadow customStyle={styles.shadow} />
</TouchableOpacity>
<Text style={styles.AttendanceSheetName} lineBreakMode={'tail'} numberOfLines={2}>
À signer {[
...new Set(attendanceSheet.slots!.map(slot => CompaniDate(slot.startDate).format(DD_MM_YYYY)))].join(', ')
}
</Text>
</View>
);

export default AttendanceSheetCell;
36 changes: 36 additions & 0 deletions src/components/learnerPendingActions/AttendanceSheetCell/styles.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { StyleSheet } from 'react-native';
import { FIRA_SANS_REGULAR } from '../../../styles/fonts';
import { YELLOW } from '../../../styles/colors';
import { BORDER_RADIUS, MARGIN, QUESTIONNAIRE_WIDTH } from '../../../styles/metrics';

const styles = StyleSheet.create({
container: {
marginVertical: MARGIN.MD,
alignItems: 'center',
width: QUESTIONNAIRE_WIDTH,
},
AttendanceSheetName: {
...FIRA_SANS_REGULAR.MD,
textAlign: 'center',
marginHorizontal: MARGIN.SM,
},
iconContainer: {
marginBottom: MARGIN.SM,
},
shadow: {
backgroundColor: YELLOW[500],
borderRadius: BORDER_RADIUS.MD,
},
icon: {
height: 64,
width: 64,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: YELLOW[300],
borderColor: YELLOW[500],
borderWidth: 1,
borderRadius: BORDER_RADIUS.MD,
},
});

export default styles;
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { View, Text, ScrollView } from 'react-native';
import React from 'react';
import { QuestionnaireType } from '../../../types/QuestionnaireType';
import QuestionnaireCell from '../QuestionnaireCell';
import styles from './styles';
import { AttendanceSheetType } from '../../../types/AttendanceSheetTypes';
import AttendanceSheetCell from '../AttendanceSheetCell';

interface PendingActionsContainerProps {
questionnaires: QuestionnaireType[],
attendanceSheets: AttendanceSheetType[],
profileId: string,
}

const PendingActionsContainer = React.memo(
({ questionnaires, attendanceSheets, profileId }: PendingActionsContainerProps) => (
<View style={styles.container}>
<Text style={styles.header}>Vous avez des actions à compléter.</Text>
<ScrollView style={styles.cellContainer} horizontal showsHorizontalScrollIndicator={false}>
{!!questionnaires.length && <QuestionnaireCell questionnaires={questionnaires} profileId={profileId} />}
{attendanceSheets.map(as => <AttendanceSheetCell key={as._id} attendanceSheet={as} />)}
</ScrollView>
</View>
)
);
export default PendingActionsContainer;
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ const styles = StyleSheet.create({
paddingVertical: PADDING.MD,
...FIRA_SANS_ITALIC.SM,
},
cellContainer: {
flexDirection: 'row',
},
});

export default styles;
18 changes: 0 additions & 18 deletions src/components/questionnaires/QuestionnairesContainer/index.tsx

This file was deleted.

38 changes: 26 additions & 12 deletions src/screens/courses/profile/LearnerCourseProfile/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-env browser */

import { useState, useEffect, useCallback } from 'react';
import { useState, useEffect, useCallback, useMemo } from 'react';
import {
View,
Text,
Expand Down Expand Up @@ -35,13 +35,13 @@ import { useGetLoggedUserId, useSetStatusBarVisible } from '../../../../store/ma
import ProgressBar from '../../../../components/cards/ProgressBar';
import CourseProfileStickyHeader from '../../../../components/CourseProfileStickyHeader';
import NiSecondaryButton from '../../../../components/form/SecondaryButton';
import QuestionnairesContainer from '../../../../components/questionnaires/QuestionnairesContainer';
import PendingActionsContainer from '../../../../components/learnerPendingActions/PendingActionsContainer';
import { QuestionnaireType } from '../../../../types/QuestionnaireType';
import { getCourseProgress } from '../../../../core/helpers/utils';
import CourseProfileHeader from '../../../../components/CourseProfileHeader';
import { FIRA_SANS_MEDIUM } from '../../../../styles/fonts';
import { renderStepList, getTitle } from '../helper';
import { IS_IOS, IS_WEB, LEARNER, PEDAGOGY } from '../../../../core/data/constants';
import { IS_IOS, IS_WEB, LEARNER, PEDAGOGY, SINGLE_COURSES_SUBPROGRAM_IDS } from '../../../../core/data/constants';

interface LearnerCourseProfileProps extends CompositeScreenProps<
StackScreenProps<RootStackParamList, 'LearnerCourseProfile'>,
Expand All @@ -59,19 +59,27 @@ const LearnerCourseProfile = ({ route, navigation }: LearnerCourseProfileProps)
const [isHeaderSticky, setIsHeaderSticky] = useState <boolean>(false);
const [progressBarY, setProgressBarY] = useState <number>(0);
const [isLoading, setIsLoading] = useState<boolean>(false);
const [title, setTitle] = useState<string>('');

const attendanceSheetsToSign = useMemo(() =>
(SINGLE_COURSES_SUBPROGRAM_IDS.includes(course?.subProgram._id || '')
? (course as BlendedCourseType)?.attendanceSheets?.filter(as =>
has(as, 'signatures.trainer') && !has(as, 'signatures.trainee')) || []
: []),
[course]);

const title = useMemo(() => getTitle(course), [course]);

const isFocused = useIsFocused();
useEffect(() => {
const getCourse = async () => {
try {
const fetchedCourse = await Courses.getCourse(route.params.courseId, PEDAGOGY);
const fetchedQuestionnaires = await Questionnaires.getUserQuestionnaires({ course: route.params.courseId });
const [fetchedCourse, fetchedQuestionnaires] = await Promise.all([
Courses.getCourse(route.params.courseId, PEDAGOGY),
Questionnaires.getUserQuestionnaires({ course: route.params.courseId }),
]);
const programImage = get(fetchedCourse, 'subProgram.program.image.link') || '';
setCourse(fetchedCourse);
setQuestionnaires(fetchedQuestionnaires);
setTitle(getTitle(fetchedCourse));

const programImage = get(fetchedCourse, 'subProgram.program.image.link') || '';
if (programImage) setSource({ uri: programImage });
} catch (e: any) {
console.error(e);
Expand Down Expand Up @@ -183,7 +191,7 @@ const LearnerCourseProfile = ({ route, navigation }: LearnerCourseProfileProps)
}
};

return course && has(course, 'subProgram.program') && (
return course && has(course, 'subProgram.program') ? (
<SafeAreaView style={commonStyles.container} edges={['top']}>
<ScrollView nestedScrollEnabled={false} showsVerticalScrollIndicator={IS_WEB}
stickyHeaderIndices={[questionnaires.length ? 3 : 2]} scrollEventThrottle={SCROLL_EVENT_THROTTLE}
Expand All @@ -193,7 +201,10 @@ const LearnerCourseProfile = ({ route, navigation }: LearnerCourseProfileProps)
<NiSecondaryButton caption='A propos' onPress={goToAbout} icon='info' borderColor={GREY[200]}
bgColor={WHITE} font={FIRA_SANS_MEDIUM.LG} />
</View>
{!!questionnaires.length && <QuestionnairesContainer questionnaires={questionnaires} profileId={course._id}/>}
{!!(questionnaires.length || attendanceSheetsToSign.length) &&
<PendingActionsContainer questionnaires={questionnaires} profileId={course._id}
attendanceSheets={attendanceSheetsToSign}/>
}
{getHeader()}
{renderStepList(course, LEARNER, route)}
{course.areLastSlotAttendancesValidated && <View style={styles.buttonContainer}>
Expand All @@ -209,7 +220,10 @@ const LearnerCourseProfile = ({ route, navigation }: LearnerCourseProfileProps)
</View>}
</ScrollView>
</SafeAreaView>
);
)
: <View style={commonStyles.loadingContainer}>
<ActivityIndicator color={GREY[800]} size="small" />
</View>;
};

export default LearnerCourseProfile;
5 changes: 5 additions & 0 deletions src/styles/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ import { WHITE, PINK, GREY } from './colors';
import { FIRA_SANS_BLACK, FIRA_SANS_BOLD, FIRA_SANS_ITALIC } from './fonts';

export default StyleSheet.create({
loadingContainer: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
},
container: {
flex: 1,
backgroundColor: WHITE,
Expand Down
1 change: 1 addition & 0 deletions src/types/AttendanceSheetTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ type BaseAttendanceSheetType = {
_id: string,
course: string,
file: { publicId: string, link: string },
slots?: SlotType[]
}

export type IntraOrIntraHoldingAttendanceSheetType = BaseAttendanceSheetType & { date: Date }
Expand Down
4 changes: 3 additions & 1 deletion src/types/CourseTypes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { UserType } from './UserType';
import { StepType, ELearningStepType } from './StepTypes';
import { CompanyType } from './CompanyType';
import { BLENDED, LEARNER, OPERATIONS, PEDAGOGY, STRICTLY_E_LEARNING, TESTER, TRAINER } from '../core/data/constants';
import { AttendanceSheetType } from './AttendanceSheetTypes';

// query
export type actionQueryCourseType = typeof PEDAGOGY | typeof OPERATIONS;
Expand Down Expand Up @@ -99,7 +100,8 @@ export type BlendedCourseType = BaseCourseType & {
companyRepresentative: UserType,
misc: string,
trainees?: TraineeType[],
companies?: CompanyType[]
companies?: CompanyType[],
attendanceSheets?: AttendanceSheetType[]
}

export type CourseModeType = typeof LEARNER | typeof TESTER | typeof TRAINER;
Expand Down
Loading