Skip to content

Commit

Permalink
Merge branch 'shiksha-2.0' of github.com:tekdi/shiksha-frontend into …
Browse files Browse the repository at this point in the history
…BugFixes
  • Loading branch information
shreyas143shinde committed Jun 5, 2024
2 parents fbe9336 + 06491c9 commit 0b81bab
Show file tree
Hide file tree
Showing 12 changed files with 154 additions and 39 deletions.
4 changes: 3 additions & 1 deletion public/locales/en/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,9 @@
"PRE_TEST": "Pre Test",
"ENGLISH": "English",
"MATH": "Math",
"TEST": "Test"
"TEST": "Test",
"ENTER_NAME": "Please Enter Full Name",
"AT_REQUIRED_LETTER":"At least one letter or underscore is required"
},

"FIELDS": {
Expand Down
4 changes: 3 additions & 1 deletion public/locales/hi/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,9 @@
"PRE_TEST": "प्री टेस्ट",
"ENGLISH": "अंग्रेजी",
"MATH": "गणित",
"TEST": "परीक्षण"
"TEST": "परीक्षण",
"ENTER_NAME": "कृपया पूरा नाम दर्ज करें",
"AT_REQUIRED_LETTER": "कम से कम एक अक्षर या अंडरस्कोर आवश्यक है"
},

"FIELDS": {
Expand Down
4 changes: 3 additions & 1 deletion public/locales/mr/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,9 @@
"PRE_TEST": "पूर्व चाचणी",
"ENGLISH": "इंग्रजी",
"MATH": "गणित",
"TEST": "चाचणी"
"TEST": "चाचणी",
"ENTER_NAME": "कृपया पूर्ण नाव प्रविष्ट करा",
"AT_REQUIRED_LETTER": "किमान एक अक्षर किंवा अंडरस्कोर आवश्यक आहे"
},
"FIELDS": {
"DESIGNATION": "पद",
Expand Down
11 changes: 8 additions & 3 deletions src/components/MarksObtainedCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,18 @@ const SmallCard: React.FC<SmallCardProps> = ({ item }) => {

return (
<Card variant="outlined" sx={{ borderRadius: '8px' }}>
<Typography fontSize={'10px'} textAlign={'center'}>
<Typography
mt={1}
fontSize={'12px'}
fontWeight={500}
lineHeight={'16px'}
textAlign={'center'}
>
{item.question}
</Typography>
<Typography
// variant="h6"
fontSize={'10px'}
fontSize={'11px'}
textAlign={'center'}
color={
item.mark_obtained > 0
Expand All @@ -45,7 +51,6 @@ const SmallCard: React.FC<SmallCardProps> = ({ item }) => {
const MarksObtainedCard: React.FC<MarksObtainedCardProps> = ({ data }) => {
const [showAllData, setShowAllData] = useState(false);
const { t } = useTranslation();


const limitedData = showAllData ? data : data?.slice(0, 12);

Expand Down
2 changes: 2 additions & 0 deletions src/pages/attendance-history.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ const UserAttendanceHistory = () => {
if (typeof window !== 'undefined' && window.localStorage) {
const token = localStorage.getItem('token');
setClassId(localStorage.getItem('classId') || '');
const classId = localStorage.getItem('classId') || '';
localStorage.setItem('cohortId', classId);
setLoading(false);
if (token) {
push('/attendance-history');
Expand Down
5 changes: 4 additions & 1 deletion src/pages/attendance-overview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,9 @@ const AttendanceOverview: React.FC<AttendanceOverviewProps> = () => {
if (typeof window !== 'undefined' && window.localStorage) {
const token = localStorage.getItem('token');
setClassId(localStorage.getItem('classId') || '');
const class_Id = localStorage.getItem('classId') || '';
localStorage.setItem('cohortId', class_Id);

setLoading(false);
if (token) {
push('/attendance-overview');
Expand Down Expand Up @@ -194,12 +197,12 @@ const AttendanceOverview: React.FC<AttendanceOverviewProps> = () => {
state: stateName,
};
});


setCohortsData(filteredData);

if (filteredData.length > 0) {
// setClassId(filteredData[0].cohortId);
localStorage.setItem('cohortId', filteredData[0]?.cohortId);

// add state name to localstorage
if (
Expand Down
11 changes: 9 additions & 2 deletions src/pages/dashboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,15 @@ const Dashboard: React.FC<DashboardProps> = () => {
?.filter(Boolean);
setCohortsData(filteredData);
if (filteredData.length > 0) {
// setClassId(filteredData?.[0]?.cohortId);
// localStorage.setItem('classId', filteredData?.[0]?.cohortId);
if (typeof window !== 'undefined' && window.localStorage) {
const cohort = localStorage.getItem('classId') || '';
if (cohort !== '') {
setClassId(localStorage.getItem('classId') || '');
} else {
localStorage.setItem('classId', filteredData?.[0]?.cohortId);
setClassId(filteredData?.[0]?.cohortId);
}
}
setManipulatedCohortData(
filteredData.concat({ cohortId: 'all', name: 'All Centers' })
);
Expand Down
79 changes: 63 additions & 16 deletions src/pages/learner/[userId].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ const LearnerProfile: React.FC = () => {
t('COMMON.AS_OF_TODAY')
);
const open = Boolean(anchorEl);
const [totalMaxScore, setTotalMaxScore] = useState('');
const [totalScore, setTotalScore] = useState('');

const [unitName, setUnitName] = useState('');
const [blockName, setBlockName] = useState('');
Expand Down Expand Up @@ -377,7 +379,8 @@ const LearnerProfile: React.FC = () => {
const result = response.result;
if (result) {
setSubmitedOn(result[0]?.createdOn);

setTotalMaxScore(result[0]?.totalMaxScore);
setTotalScore(result[0]?.totalScore);
const questionValues = getQuestionValues(result);
setAssesmentData(questionValues?.questions); // Use the parsed questions
setLoading(false);
Expand Down Expand Up @@ -559,6 +562,23 @@ const LearnerProfile: React.FC = () => {
}));
};

const [hasErrors, setHasErrors] = useState(false);

const handleInputChange = (e: React.ChangeEvent<HTMLInputElement>) => {
const { value } = e.target;
const sanitizedValue = value.replace(/[^a-zA-Z_ ]/g, '');

setFormData((prevData) => ({
...prevData,
userData: {
...prevData.userData,
name: sanitizedValue,
},
}));

setHasErrors(!sanitizedValue.trim());
};

const handleSubmit = async (
e: React.MouseEvent<HTMLButtonElement, MouseEvent>
) => {
Expand Down Expand Up @@ -867,7 +887,7 @@ const LearnerProfile: React.FC = () => {
flex: '1',
border: '2px solid',
borderColor: '#FFECB3',
padding: '10px',
padding: '15px',
}}
minWidth={'100%'}
borderRadius={'12px'}
Expand Down Expand Up @@ -991,8 +1011,7 @@ const LearnerProfile: React.FC = () => {
{uniqueDoId ? (
<Box
sx={{
background:
'linear-gradient(180deg, #FFFDF6 0%, #F8EFDA 100%)',
background: '#F8EFE7',
p: 2,
}}
>
Expand All @@ -1009,7 +1028,8 @@ const LearnerProfile: React.FC = () => {
{t('PROFILE.MARK_OBTAINED')}
</Typography>
<Typography variant="h4" fontWeight={'bold'}>
{/* 60/70 */}
{totalScore ? totalScore : '0'}/
{totalMaxScore ? totalMaxScore : '0'}
</Typography>
</Box>
<Divider />
Expand Down Expand Up @@ -1140,24 +1160,50 @@ const LearnerProfile: React.FC = () => {
label={t('PROFILE.FULL_NAME')}
variant="outlined"
value={formData.userData.name}
onChange={(e) =>
setFormData({
...formData,
userData: {
name: e.target.value,
district: '',
state: '',
mobile: '',
},
})
inputProps={{
pattern: '^[A-Za-z_ ]+$', // Only allow letters, underscores, and spaces
title: t('PROFILE.AT_REQUIRED_LETTER'),
required: true,
}}
error={!formData.userData.name.trim()} // Show error if the input is empty
helperText={
!formData.userData.name.trim() && t('PROFILE.ENTER_NAME')
}
onChange={handleInputChange}
/>

{filteredSortedForEdit
?.filter((field) => field.isEditable)
?.map((field) => (
<Grid item xs={12} key={field.fieldId}>
{field.type === 'text' || field.type === 'numeric' ? (
{field.type === 'text' ? (
<TextField
type="text"
sx={{ marginTop: '20px' }}
fullWidth
name={field.name}
// label={field.label}
label={
field?.label && field.name
? t(`FIELDS.${field.name.toUpperCase()}`, field.label)
: field.label
}
variant="outlined"
inputProps={{
pattern: '^[A-Za-z_ ]+$', // Only allow letters, underscores, and spaces
title: 'At least one letter or underscore is required',
required: true,
}}
value={
formData.customFields.find(
(f) => f.fieldId === field.fieldId
)?.value[0] || ''
}
onChange={(e) => {
handleFieldChange(field.fieldId, e.target.value);
}}
/>
) : field.type === 'numeric' ? (
<TextField
type="number"
sx={{ marginTop: '20px' }}
Expand Down Expand Up @@ -1317,6 +1363,7 @@ const LearnerProfile: React.FC = () => {
}}
onClick={handleSubmit}
variant="contained"
disabled={hasErrors}
>
{t('COMMON.SAVE')}
</Button>
Expand Down
4 changes: 2 additions & 2 deletions src/pages/login.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -307,15 +307,15 @@ const LoginPage = () => {
/>
</Box>

<Box marginTop={'1rem'} marginLeft={'0.8rem'}>
{/* <Box marginTop={'1rem'} marginLeft={'0.8rem'}>
<Link
sx={{ color: theme.palette.secondary.main }}
href="https://qa.prathamteacherapp.tekdinext.com/auth/realms/pratham/login-actions/reset-credentials?client_id=security-admin-console&tab_id=R-3zEZbbbyM"
underline="none"
>
{t('LOGIN_PAGE.FORGOT_PASSWORD')}
</Link>
</Box>
</Box> */}
<Box marginTop={'1.2rem'} className="remember-me-checkbox">
<Checkbox
onChange={(e) => setRememberMe(e.target.checked)}
Expand Down
1 change: 1 addition & 0 deletions src/pages/logout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ function Logout() {
localStorage.removeItem('userId');
localStorage.removeItem('parentCohortId');
localStorage.removeItem('learnerId');
localStorage.removeItem('classId');

router.replace('/login');
}, []);
Expand Down
66 changes: 55 additions & 11 deletions src/pages/profile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,23 @@ const TeacherProfile = () => {
});
}, [userData, customFieldsData]);

const [hasErrors, setHasErrors] = useState(false);

const handleInputChange = (e: React.ChangeEvent<HTMLInputElement>) => {
const { value } = e.target;
const sanitizedValue = value.replace(/[^a-zA-Z_ ]/g, '');

setFormData((prevData) => ({
...prevData,
userData: {
...prevData.userData,
name: sanitizedValue,
},
}));

setHasErrors(!sanitizedValue.trim());
};

const handleFieldChange = (fieldId: string, value: string) => {
setFormData((prevState) => ({
...prevState,
Expand Down Expand Up @@ -752,30 +769,56 @@ const TeacherProfile = () => {
</Box>
<TextField
sx={{ marginTop: '20px' }}
type="text"
fullWidth
name="name"
label={t('PROFILE.FULL_NAME')}
variant="outlined"
value={formData.userData.name}
onChange={(e) =>
setFormData({
...formData,
userData: {
name: e.target.value,
district: '',
state: '',
mobile: '',
},
})
inputProps={{
pattern: '^[A-Za-z_ ]+$', // Only allow letters, underscores, and spaces
title: t('PROFILE.AT_REQUIRED_LETTER'),
required: true,
}}
error={!formData.userData.name.trim()} // Show error if the input is empty
helperText={
!formData.userData.name.trim() && t('PROFILE.ENTER_NAME')
}
onChange={handleInputChange}
/>

{customFieldsData
?.filter((field) => field.isEditable)
?.sort((a, b) => a.order - b.order)
?.map((field) => (
<Grid item xs={12} key={field.fieldId}>
{field.type === 'text' || field.type === 'numeric' ? (
{field.type === 'text' ? (
<TextField
type="text"
inputProps={{ maxLength: 3 }}
sx={{ marginTop: '20px' }}
fullWidth
name={field.name}
// label={field.label}
label={
field?.label && field.name
? t(
`FIELDS.${field.name.toUpperCase()}`,
field.label
)
: field.label
}
variant="outlined"
value={
formData?.customFields?.find(
(f) => f.fieldId === field.fieldId
)?.value[0] || ''
}
onChange={(e) => {
handleFieldChange(field.fieldId, e.target.value);
}}
/>
) : field.type === 'numeric' ? (
<TextField
type="number"
inputProps={{ maxLength: 3 }}
Expand Down Expand Up @@ -951,6 +994,7 @@ const TeacherProfile = () => {
}}
onClick={handleSubmit}
variant="contained"
disabled={hasErrors}
>
{t('COMMON.SAVE')}
</Button>
Expand Down
2 changes: 1 addition & 1 deletion src/utils/Interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ export interface CustomField {
label: string;
value: string;
options: Record<string, any>;
type: string;
type: any;
order: number;
name: string;
isEditable: boolean;
Expand Down

0 comments on commit 0b81bab

Please sign in to comment.