Skip to content

Commit

Permalink
i18n and label
Browse files Browse the repository at this point in the history
  • Loading branch information
JibrilExe committed Mar 31, 2024
1 parent 94e68d6 commit 3b8af4d
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
5 changes: 4 additions & 1 deletion frontend/public/locales/en/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,8 @@
"myProjects": "My Projects",
"myCourses": "My Courses",
"login": "Login",
"home": "Home"
"home": "Home",
"courseName": "Course Name",
"submit": "Submit",
"emptyCourseName": "Course name should not be empty"
}
5 changes: 4 additions & 1 deletion frontend/public/locales/nl/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,8 @@
"myProjects": "Mijn Projecten",
"myCourses": "Mijn Vakken",
"login": "Login",
"home": "Home"
"home": "Home",
"courseName": "Vak Naam",
"submit": "Opslaan",
"emptyCourseName": "Vak naam mag niet leeg zijn"
}
11 changes: 7 additions & 4 deletions frontend/src/components/Courses/CourseForm.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React from 'react';
import { useState } from 'react';
import { FormControl, Box, TextField, Button} from '@mui/material';
import { FormControl, Box, TextField, Button, FormLabel} from '@mui/material';
import { useTranslation } from 'react-i18next';

/**
* Renders the CourseForm component.
Expand All @@ -10,6 +11,8 @@ export function CourseForm(): JSX.Element {
const [courseName, setCourseName] = useState('');
const [error, setError] = useState('');

const { t } = useTranslation();

const apiHost = import.meta.env.VITE_API_HOST;

const handleInputChange = (event: React.ChangeEvent<HTMLInputElement>) => {
Expand All @@ -21,7 +24,7 @@ export function CourseForm(): JSX.Element {
e.preventDefault(); // Prevents the default form submission behaviour

if (!courseName.trim()) {
setError('Course name should not be empty');
setError(t('emptyCourseName'));
return;
}

Expand All @@ -33,8 +36,8 @@ export function CourseForm(): JSX.Element {
<Box display="flex" justifyContent="center" alignItems="center" height="90vh" position="relative">
<form onSubmit={handleSubmit}>
<FormControl>
<FormLabel htmlFor="course-name">{t('courseName')}</FormLabel>
<TextField
label="course name"
value={courseName}
onChange={handleInputChange}
error={!!error} // Applying error style if there's an error message
Expand All @@ -50,7 +53,7 @@ export function CourseForm(): JSX.Element {
right: '30rem',
}}
>
Submit
{t('submit')}
</Button>
</form>
</Box>
Expand Down

0 comments on commit 3b8af4d

Please sign in to comment.