Skip to content

Commit

Permalink
Add more stuff.
Browse files Browse the repository at this point in the history
Signed-off-by: Aliwoto <aminnimaj@gmail.com>
  • Loading branch information
ALiwoto committed Aug 20, 2024
1 parent 0ff6671 commit d3a1e82
Show file tree
Hide file tree
Showing 6 changed files with 111 additions and 10 deletions.
Binary file added public/examsphere-intro.mp4
Binary file not shown.
Binary file added public/examsphere-pic.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
65 changes: 64 additions & 1 deletion src/api/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ export const APIErrorCode = {
ErrCodeInvalidCaptcha: 2138,
ErrCodeQueryParameterNotProvided: 2139,
ErrCodeTooManyPasswordChangeAttempts: 2140,
ErrCodeRequestExpired: 2141
ErrCodeRequestExpired: 2141,
ErrCodeInvalidEmail: 2142
} as const;

export type APIErrorCode = typeof APIErrorCode[keyof typeof APIErrorCode];
Expand Down Expand Up @@ -307,6 +308,38 @@ export interface ConfirmChangePasswordData {
*/
'rt_verifier'?: string;
}
/**
*
* @export
* @interface CreateNewTopicData
*/
export interface CreateNewTopicData {
/**
*
* @type {string}
* @memberof CreateNewTopicData
*/
'topicName'?: string;
}
/**
*
* @export
* @interface CreateNewTopicResult
*/
export interface CreateNewTopicResult {
/**
*
* @type {number}
* @memberof CreateNewTopicResult
*/
'topicID'?: number;
/**
*
* @type {string}
* @memberof CreateNewTopicResult
*/
'topicName'?: string;
}
/**
*
* @export
Expand All @@ -331,12 +364,30 @@ export interface CreateUserData {
* @memberof CreateUserData
*/
'password'?: string;
/**
*
* @type {string}
* @memberof CreateUserData
*/
'phone_number'?: string;
/**
*
* @type {UserRole}
* @memberof CreateUserData
*/
'role'?: UserRole;
/**
*
* @type {boolean}
* @memberof CreateUserData
*/
'setup_completed'?: boolean;
/**
*
* @type {string}
* @memberof CreateUserData
*/
'user_address'?: string;
/**
*
* @type {string}
Expand Down Expand Up @@ -420,6 +471,18 @@ export interface EditUserData {
* @memberof EditUserData
*/
'full_name'?: string;
/**
*
* @type {string}
* @memberof EditUserData
*/
'phone_number'?: string;
/**
*
* @type {string}
* @memberof EditUserData
*/
'user_address'?: string;
/**
*
* @type {string}
Expand Down
52 changes: 43 additions & 9 deletions src/pages/createUserPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ import SelectMenu from '../components/menus/selectMenu';
import apiClient from '../apiClient';
import { CreateUserData, UserRole } from '../api';
import { CurrentAppTranslation } from '../translations/appTranslation';
import { TextField } from '@mui/material';
import { Checkbox, FormControlLabel, TextField } from '@mui/material';
import useAppSnackbar from '../components/snackbars/useAppSnackbars';
import { extractErrorDetails } from '../utils/errorUtils';

const CreateUserPage: React.FC = () => {
const [userInfo, setUserInfo] = useState<CreateUserData>({
const [createUserData, setUserInfo] = useState<CreateUserData>({
user_id: '',
email: '',
password: '',
Expand All @@ -22,14 +22,14 @@ const CreateUserPage: React.FC = () => {
const snackbar = useAppSnackbar();

const handleInputChange = (e: React.ChangeEvent<HTMLInputElement | HTMLSelectElement>) => {
setUserInfo({ ...userInfo, [e.target.name]: e.target.value });
setUserInfo({ ...createUserData, [e.target.name]: e.target.value });
};

const handleSubmit = async (e: React.FormEvent) => {
e.preventDefault();

try {
await apiClient.createNewUser(userInfo);
await apiClient.createNewUser(createUserData);
snackbar.success(CurrentAppTranslation.UserCreatedSuccessfullyText);
} catch (error: any) {
const [errCode, errMessage] = extractErrorDetails(error);
Expand All @@ -50,7 +50,7 @@ const CreateUserPage: React.FC = () => {
name="user_id"
variant='standard'
label={CurrentAppTranslation.user_id}
value={userInfo.user_id ?? ''}
value={createUserData.user_id ?? ''}
onChange={(e) => { handleInputChange(e as any) }}
required />
<TextField
Expand All @@ -61,7 +61,7 @@ const CreateUserPage: React.FC = () => {
name="full_name"
variant='standard'
label={CurrentAppTranslation.full_name}
value={userInfo.full_name ?? ''}
value={createUserData.full_name ?? ''}
onChange={(e) => { handleInputChange(e as any) }}
required />
<TextField
Expand All @@ -73,7 +73,7 @@ const CreateUserPage: React.FC = () => {
variant='standard'
type="email"
label={CurrentAppTranslation.email}
value={userInfo.email ?? ''}
value={createUserData.email ?? ''}
onChange={(e) => { handleInputChange(e as any) }}
required />
<TextField
Expand All @@ -85,17 +85,51 @@ const CreateUserPage: React.FC = () => {
variant='standard'
type="password"
label={CurrentAppTranslation.password}
value={userInfo.password ?? ''}
value={createUserData.password ?? ''}
onChange={(e) => { handleInputChange(e as any) }}
required />
<SelectMenu
labelText='Role'
labelId='role-select-label'
name={CurrentAppTranslation.role}
value={userInfo.role ?? UserRole.UserRoleStudent}
value={createUserData.role ?? UserRole.UserRoleStudent}
onChange={handleInputChange}
options={Object.values(UserRole).filter(role => apiClient.canCreateTargetRole(role))}
/>
<FormControlLabel
control={
<Checkbox
checked={createUserData.setup_completed ?? true}
onChange={(e) => setUserInfo({ ...createUserData, setup_completed: e.target.checked })}
color="primary"
/>
}
label="Send email confirmation to user"
/>
<TextField
style={{
width: '100%',
marginBottom: '1rem'
}}
name="phone_number"
variant='standard'
type="tel"
label={CurrentAppTranslation.phone_number}
value={createUserData.phone_number ?? ''}
onChange={(e) => { handleInputChange(e as any) }}
required={false} />
<TextField
style={{
width: '100%',
marginBottom: '1rem'
}}
name="user_address"
variant='standard'
type='text'
label={CurrentAppTranslation.user_address}
value={createUserData.user_address ?? ''}
onChange={(e) => { handleInputChange(e as any) }}
required={false} />
<SubmitButton type="submit">{CurrentAppTranslation.CreateUserButtonText}</SubmitButton>
</CreateUserForm>
</CreateUserContainer>
Expand Down
2 changes: 2 additions & 0 deletions src/translations/appTranslation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ export class AppTranslationBase {
full_name: string = "Full Name";
email: string = "Email";
password: string = "Password";
phone_number: string = "Phone Number";
user_address: string = "Address";
created_at: string = "Created At";
updated_at: string = "Updated At";
last_login: string = "Last Login";
Expand Down
2 changes: 2 additions & 0 deletions src/translations/faTranslation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ class FaTranslation extends AppTranslationBase {
full_name: string = "نام کامل";
email: string = "ایمیل";
password: string = "رمز عبور";
phone_number: string = "تلفن همراه";
user_address: string = "آدرس";
created_at: string = "ایجاد شده در";
updated_at: string = "به روز شده در";
last_login: string = "آخرین ورود";
Expand Down

0 comments on commit d3a1e82

Please sign in to comment.