Skip to content

Commit

Permalink
Merge pull request #243 from upendraTekdi/shiksha-2.0
Browse files Browse the repository at this point in the history
Issue #PS-316 feat:set validation for text , numeric and update cohortId set for assesment tracking api
  • Loading branch information
itsvick authored Jun 5, 2024
2 parents 381b543 + cc756c7 commit 2efe9c6
Show file tree
Hide file tree
Showing 9 changed files with 142 additions and 35 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
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
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 @@ -731,30 +748,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 @@ -930,6 +973,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 2efe9c6

Please sign in to comment.