eli02 commited on
Commit
0056542
Β·
1 Parent(s): bdd9b98

feat: Add user type selection to Login component and update useAuth hook to manage user type

Browse files
src/components/Auth/Login.jsx CHANGED
@@ -1,7 +1,7 @@
1
- import React, { useState } from 'react';
2
  import { useNavigate } from 'react-router-dom';
3
  import { useAuth } from '../../hooks/useAuth';
4
- import { Button, TextField, Box, Typography, Paper, CircularProgress } from '@mui/material';
5
  import styled from '@emotion/styled';
6
 
7
  const StyledPaper = styled(Paper)(({ theme }) => ({
@@ -16,7 +16,8 @@ const Login = () => {
16
  const [password, setPassword] = useState('');
17
  const [error, setError] = useState('');
18
  const [loading, setLoading] = useState(false);
19
- const { login } = useAuth();
 
20
  const navigate = useNavigate();
21
 
22
  const handleSubmit = async (e) => {
@@ -38,6 +39,12 @@ const Login = () => {
38
  }
39
  };
40
 
 
 
 
 
 
 
41
  return (
42
  <StyledPaper elevation={3}>
43
  <Typography variant="h4" gutterBottom align="center" sx={{ fontWeight: 'bold' }}>
@@ -73,6 +80,21 @@ const Login = () => {
73
  onChange={(e) => setPassword(e.target.value)}
74
  required
75
  />
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
76
  <Button
77
  fullWidth
78
  type="submit"
 
1
+ import React, { useState, useEffect } from 'react';
2
  import { useNavigate } from 'react-router-dom';
3
  import { useAuth } from '../../hooks/useAuth';
4
+ import { Button, TextField, Box, Typography, Paper, CircularProgress, FormControl, InputLabel, Select, MenuItem } from '@mui/material';
5
  import styled from '@emotion/styled';
6
 
7
  const StyledPaper = styled(Paper)(({ theme }) => ({
 
16
  const [password, setPassword] = useState('');
17
  const [error, setError] = useState('');
18
  const [loading, setLoading] = useState(false);
19
+ const { login, setUserType } = useAuth();
20
+ const [selectedUserType, setSelectedUserType] = useState('Enthusiast');
21
  const navigate = useNavigate();
22
 
23
  const handleSubmit = async (e) => {
 
39
  }
40
  };
41
 
42
+ useEffect(() => {
43
+ if (!loading && !error && selectedUserType) {
44
+ setUserType(selectedUserType);
45
+ }
46
+ }, [loading, error, selectedUserType, setUserType]);
47
+
48
  return (
49
  <StyledPaper elevation={3}>
50
  <Typography variant="h4" gutterBottom align="center" sx={{ fontWeight: 'bold' }}>
 
80
  onChange={(e) => setPassword(e.target.value)}
81
  required
82
  />
83
+ {/* User type selector */}
84
+ <Box sx={{ mt: 2 }}>
85
+ <FormControl fullWidth>
86
+ <InputLabel id="user-type-label">User Type</InputLabel>
87
+ <Select
88
+ labelId="user-type-label"
89
+ value={selectedUserType}
90
+ label="User Type"
91
+ onChange={(e) => setSelectedUserType(e.target.value)}
92
+ >
93
+ <MenuItem value="Enthusiast">Enthusiast</MenuItem>
94
+ <MenuItem value="Ustaz">Ustaz</MenuItem>
95
+ </Select>
96
+ </FormControl>
97
+ </Box>
98
  <Button
99
  fullWidth
100
  type="submit"
src/components/Search/FeedbackForm.jsx CHANGED
@@ -24,7 +24,7 @@ const StyledPaper = styled(Paper)(({ theme }) => ({
24
  }));
25
 
26
  const FeedbackForm = ({ searchResult, query, onFeedbackSubmitted }) => {
27
- const { user, authTokens } = useAuth();
28
  const [reaction, setReaction] = useState('');
29
  const [confidence, setConfidence] = useState(5);
30
  const [rating, setRating] = useState(3);
@@ -46,8 +46,8 @@ const FeedbackForm = ({ searchResult, query, onFeedbackSubmitted }) => {
46
  try {
47
  // Extract only the needed properties for the backend
48
  const feedbackData = {
49
- user_type: 'user',
50
- username: user || 'anonymous',
51
  query: query || '',
52
  retrieved_text: searchResult.content || searchResult.text || JSON.stringify(searchResult),
53
  model_type: searchResult.model_type || 'unknown',
@@ -99,9 +99,9 @@ const FeedbackForm = ({ searchResult, query, onFeedbackSubmitted }) => {
99
  value={reaction}
100
  onChange={(e) => setReaction(e.target.value)}
101
  >
102
- <FormControlLabel value="relevant" control={<Radio />} label="Relevant" />
103
- <FormControlLabel value="somewhat_relevant" control={<Radio />} label="Somewhat Relevant" />
104
- <FormControlLabel value="not_relevant" control={<Radio />} label="Not Relevant" />
105
  </RadioGroup>
106
  </FormControl>
107
 
 
24
  }));
25
 
26
  const FeedbackForm = ({ searchResult, query, onFeedbackSubmitted }) => {
27
+ const { user, authTokens, userType } = useAuth();
28
  const [reaction, setReaction] = useState('');
29
  const [confidence, setConfidence] = useState(5);
30
  const [rating, setRating] = useState(3);
 
46
  try {
47
  // Extract only the needed properties for the backend
48
  const feedbackData = {
49
+ user_type: userType,
50
+ username: user,
51
  query: query || '',
52
  retrieved_text: searchResult.content || searchResult.text || JSON.stringify(searchResult),
53
  model_type: searchResult.model_type || 'unknown',
 
99
  value={reaction}
100
  onChange={(e) => setReaction(e.target.value)}
101
  >
102
+ <FormControlLabel value="πŸ‘" control={<Radio />} label="πŸ‘" />
103
+ <FormControlLabel value="πŸ€·β€β™‚οΈ" control={<Radio />} label="πŸ€·β€β™‚οΈ" />
104
+ <FormControlLabel value="πŸ‘Ž" control={<Radio />} label="πŸ‘Ž" />
105
  </RadioGroup>
106
  </FormControl>
107
 
src/hooks/useAuth.js CHANGED
@@ -9,6 +9,7 @@ const AuthContext = createContext();
9
  export const AuthProvider = ({ children }) => {
10
  const [user, setUser] = useState(null);
11
  const [authTokens, setAuthTokens] = useLocalStorage('authTokens', null);
 
12
  const [isRefreshing, setIsRefreshing] = useState(false);
13
  const navigate = useNavigate();
14
 
@@ -100,6 +101,8 @@ export const AuthProvider = ({ children }) => {
100
  const value = {
101
  user,
102
  authTokens,
 
 
103
  isAuthenticated: !!authTokens?.access,
104
  isRefreshing,
105
  login,
 
9
  export const AuthProvider = ({ children }) => {
10
  const [user, setUser] = useState(null);
11
  const [authTokens, setAuthTokens] = useLocalStorage('authTokens', null);
12
+ const [userType, setUserType] = useLocalStorage('userType', 'Enthusiast');
13
  const [isRefreshing, setIsRefreshing] = useState(false);
14
  const navigate = useNavigate();
15
 
 
101
  const value = {
102
  user,
103
  authTokens,
104
+ userType,
105
+ setUserType,
106
  isAuthenticated: !!authTokens?.access,
107
  isRefreshing,
108
  login,