Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add profile page, edit profile modal , view quiz report page and fix social media handles on register page #54

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import CheckQuiz from '@checkQuiz/views/checkQuiz'
import CheckQuestionView from '@checkQuiz/components/giveQuiz/CheckQuestionView'
import { TimerProvider } from './modules/giveQuiz/components/TimerContext'
import Spin from '@common/components/Spinner';
import ProfilePage from './modules/profilePage/views/profilePage'
import ViewReport from './modules/viewReport/views/viewReport'

function App() {
const authStore = useAuthStore()
Expand Down Expand Up @@ -63,6 +65,8 @@ function App() {
<Route path='/give-quiz/:quizId' element={<GiveQuiz />} />
<Route path='/check-quiz/:quizId/:questionIdParam' element={<CheckQuestionView />} />
<Route path='/check-quiz/:quizId' element={<CheckQuiz />} />
<Route path='/profile' element={<ProfilePage />} />
<Route path='/view-report/:quizId' element={<ViewReport />} />
<Route path='/*' element={<Navigate to='/dashboard' />} />
</>
) : null}
Expand Down
4 changes: 4 additions & 0 deletions src/assets/images/correct.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions src/assets/images/incorrect.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions src/assets/images/mdi_gmail.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions src/assets/images/mdi_phone.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions src/assets/images/partial.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions src/assets/images/unattempted.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion src/common/components/TopNav.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ const TopNav = ({ isDashboard = false, isAdmin = false }: TopNavProps) => {
)}
{isDashboard && (
<>
<Avatar name='User Name' src={profileUrl} size='sm' />
<Avatar name='User Name' src={profileUrl} size='sm' onClick={() => {navigate('/profile')}}/>
</>
)}
</HStack>
Expand Down
4 changes: 2 additions & 2 deletions src/modules/auth/api/authFetcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ export const checkAuth = async () => {
export const onboard = async ({
personalDetails,
educationalDetails,
socialMediaHandles,
socialHandles,
user,
}: any) => {
try {
const res = await axiosInstance.post('auth/onboard', {
personalDetails,
educationalDetails,
socialMediaHandles,
socialHandles,
user,
})
return res.data
Expand Down
19 changes: 16 additions & 3 deletions src/modules/auth/forms/SocialHandles.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,12 @@ interface SocialMediaOption {
icon?: JSX.Element
}

const socialMediaOptions: SocialMediaOption[] = [
interface SocialMedia {
type: string
handle: string
}

export const socialMediaOptions: SocialMediaOption[] = [
{ value: '', label: 'Select...' },
{ value: 'github', label: 'GitHub', icon: <GithubIconPurple /> },
{ value: 'codeforces', label: 'Code Forces', icon: <CodeForcesIcon /> },
Expand All @@ -53,7 +58,7 @@ const socialMediaOptions: SocialMediaOption[] = [
{ value: 'facebook', label: 'Facebook', icon: <FacebookIcon /> },
]

const CustomOptionComponent: React.FC<any> = ({ innerProps, label, data }) => (
export const CustomOptionComponent: React.FC<any> = ({ innerProps, label, data }) => (
<Stack
direction={'row'}
px={2}
Expand Down Expand Up @@ -150,6 +155,14 @@ export const SocialHandlesForm = (props: FormProps) => {
phoneNo: phone,
}

const socialHandles: SocialMedia[] = []
socialMediaHandles.map((socialHandle: any, key: number) => {
socialHandles.push({
type: socialHandle.platformValue,
handle: socialHandle.link
})
})

const educationalDetails = {
instituteName: org,
country: country,
Expand All @@ -161,7 +174,7 @@ export const SocialHandlesForm = (props: FormProps) => {
{
personalDetails,
educationalDetails,
socialMediaHandles,
socialHandles,
user,
},
{
Expand Down
2 changes: 1 addition & 1 deletion src/modules/giveQuiz/components/QuestionView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
import { SubmitQuizModal } from './Modals/SubmitQuizModal'
import { useParams } from 'react-router-dom'
import { Option,ResponseStatus } from '../../types'
import Fetching from '../../../animations/Fetching'
import Fetching from '../../../animations/Fetching.jsx'
import removeFromArray from '@giveQuiz/utils/removeFromArray'
import { useQueryClient } from '@tanstack/react-query'
import { handleSaveButton } from '@giveQuiz/utils/handleSaveButton'
Expand Down
20 changes: 20 additions & 0 deletions src/modules/profilePage/api/axiosInstance.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import axios from 'axios'
import { baseURL } from '../../../config/config'
import Cookies from 'js-cookie'

const axiosInstance = axios.create({
headers: {
'Content-Type': 'application/json',
Accept: 'application/json',
},
baseURL,
withCredentials: true,
})

axiosInstance.interceptors.request.use((config) => {
const { jwtToken } = Cookies.get()
config.headers.Authorization = `Bearer ${jwtToken}`
return config
})

export default axiosInstance
22 changes: 22 additions & 0 deletions src/modules/profilePage/api/useProfilePage.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { useQuery } from '@tanstack/react-query'
import axios from 'axios'
import axiosInstance from '../../auth/api/axiosInstance'

export const useProfilePage = () => {
const query = useQuery({
queryKey: ['profilePage'],
queryFn: async () => {
try {
const res = await axiosInstance.get('/profile')
return res.data
} catch (e: unknown) {
if (axios.isAxiosError(e)) {
return e.response?.data || e.message
}
throw e
}
},
staleTime: 1000 * 60 * 60 * 3,
})
return query
}
9 changes: 9 additions & 0 deletions src/modules/profilePage/api/useUser.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { useMutation } from '@tanstack/react-query'
import * as fetchers from './userUpdate'

export const useUpdateUser = () => {
const mutation = useMutation({
mutationFn: fetchers.userUpdate,
})
return mutation
}
24 changes: 24 additions & 0 deletions src/modules/profilePage/api/userUpdate.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import axios from 'axios'
import axiosInstance from './axiosInstance'

export const userUpdate = async ({
personalDetails,
educationalDetails,
socialHandles,
user,
}: any) => {
try {
const res = await axiosInstance.post('profile/update', {
personalDetails,
educationalDetails,
socialHandles,
user,
})
return res.data
} catch (e: unknown) {
if (axios.isAxiosError(e)) {
return e.response?.data || e.message
}
throw e
}
}
Loading