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

baseurl added #88

Merged
merged 3 commits into from
Jan 1, 2024
Merged
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
2 changes: 1 addition & 1 deletion .github/workflows/deployer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Deploy to GitHub Pages
on:
push:
branches:
- main
- publish
workflow_dispatch:
permissions:
contents: read
Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
"homepage": "https://kushwahramkumar2003.github.io/Online-Quiz",
"version": "0.1.0",
"private": true,
"proxy": "https://quiz-app-test-01.azurewebsites.net/",
"dependencies": {
"@reduxjs/toolkit": "^2.0.1",
"@svgr/webpack": "^8.1.0",
Expand Down
2 changes: 1 addition & 1 deletion src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ function App() {
return (
<div>
<Routes>
<Route path="/Online-Quiz" element={<Home />}></Route>
<Route path="/" element={<Home />}></Route>
<Route exact path="/login" element={<Login />}></Route>
<Route exact path="/SignUp" element={<Signup />}></Route>
<Route exact path="/User" element={<UserPage />}></Route>
Expand Down
6 changes: 3 additions & 3 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from "react";
import ReactDOM from "react-dom/client";
import { BrowserRouter } from "react-router-dom";
import { HashRouter } from "react-router-dom";
import { QueryClientProvider, QueryClient } from "@tanstack/react-query";
import { Provider } from "react-redux";
import { Toaster } from "react-hot-toast";
Expand All @@ -12,12 +12,12 @@ const queryClient = new QueryClient();

const root = ReactDOM.createRoot(document.getElementById("root"));
root.render(
<BrowserRouter>
<HashRouter>
<Provider store={store}>
<QueryClientProvider client={queryClient}>
<App className="transition-all scroll-smooth " />
<Toaster />
</QueryClientProvider>
</Provider>
</BrowserRouter>
</HashRouter>
);
8 changes: 4 additions & 4 deletions src/pages/login/login.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@ export default function Login() {
color: "black",
};

const { mutate} = useMutation({
const { mutate } = useMutation({
mutationFn: ({ email, password }) => {
return login({ email, password });
},
onSuccess: (data) => {
onSuccess: async (data) => {
const { user } = data;

dispatch(userActions.setUserInfo(data.user));
localStorage.setItem("account", JSON.stringify(data));
await dispatch(userActions.setUserInfo(data.user));
await localStorage.setItem("account", JSON.stringify(data));
toast.success("Login successfully");

// console.log("User.role : ", user.role);
Expand Down
8 changes: 8 additions & 0 deletions src/services/baseUrl.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import axios from "axios";

const api = axios.create({
baseURL: "https://quiz-app-test-01.azurewebsites.net",
// baseURL: "http://localhost:3001",
});

export default api;
4 changes: 2 additions & 2 deletions src/services/feedback.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import axios from "axios";
import api from "./baseUrl";

export const submitFeedback = async (formData) => {
try {
// Assuming you have a backend endpoint to handle feedback submission
const { data } = await axios.post("/api/v1/feedback/submit", formData);
const { data } = await api.post("/api/v1/feedback/submit", formData);
// Optionally, you can add logic to handle success (e.g., redirect)
return data;
} catch (error) {
Expand Down
26 changes: 14 additions & 12 deletions src/services/quiz.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import axios from "axios";
import api from "./baseUrl";

export const createNewQuiz = async ({
title,
Expand All @@ -14,7 +14,7 @@ export const createNewQuiz = async ({
console.log("Level", level);

try {
const { data } = await axios.post("/api/v1/quiz/create", {
const { data } = await api.post("/api/v1/quiz/create", {
title,
description,
category,
Expand All @@ -41,7 +41,7 @@ export const addQuestionInQuiz = async ({
console.log("Question", question);
console.log("Options", options);
console.log("Correct Answer", correctAnswer);
const { data } = await axios.post(
const { data } = await api.post(
`/api/v1/quiz//create/addQuestion/${quizId}`,
{
question,
Expand All @@ -60,7 +60,9 @@ export const addQuestionInQuiz = async ({

export const getAllQuizs = async () => {
try {
const { data } = await axios.get(`/api/v1/quiz`);
const { data } = await api.get(`/api/v1/quiz`, {
withCredentials: true,
});
console.log("All Quezzes", data);
return data;
} catch (error) {
Expand All @@ -74,7 +76,7 @@ export const getAllQuizs = async () => {
export const getQuizById = async ({ quizId }) => {
try {
console.log("Quiz Id", quizId);
const { data } = await axios.get(`/api/v1/quiz/${quizId}`);
const { data } = await api.get(`/api/v1/quiz/${quizId}`);
return data;
} catch (error) {
if (error.response) {
Expand All @@ -86,7 +88,7 @@ export const getQuizById = async ({ quizId }) => {

export const updateQuizById = async ({ title, quizId }) => {
try {
const { data } = await axios.put(`/api/v1/quiz/${quizId}/update`, {
const { data } = await api.put(`/api/v1/quiz/${quizId}/update`, {
title,
});
return data;
Expand All @@ -106,7 +108,7 @@ export const updateQuestionByQuizId = async ({
correctAnswer,
}) => {
try {
const { data } = await axios.put(
const { data } = await api.put(
`/api/v1/quiz/${quizId}/question/${questionId}/update`,
{
question,
Expand All @@ -125,7 +127,7 @@ export const updateQuestionByQuizId = async ({

export const deleteQuiz = async ({ quizId }) => {
try {
const { data } = await axios.delete(`/api/v1/quiz/${quizId}/delete`);
const { data } = await api.delete(`/api/v1/quiz/${quizId}/delete`);
return data;
} catch (error) {
if (error.response) {
Expand All @@ -137,7 +139,7 @@ export const deleteQuiz = async ({ quizId }) => {

export const deleteQuestionByQuizId = async ({ quizId, questionId }) => {
try {
const { data } = await axios.delete(
const { data } = await api.delete(
`/api/v1/quiz/${quizId}/question/${questionId}/delete`
);
return data;
Expand All @@ -149,10 +151,10 @@ export const deleteQuestionByQuizId = async ({ quizId, questionId }) => {
}
};

export const publishQuiz = async ({ quizId,publish }) => {
export const publishQuiz = async ({ quizId, publish }) => {
try {
const { data } = await axios.put(`/api/v1/quiz/${quizId}/publish`, {
publish
const { data } = await api.put(`/api/v1/quiz/${quizId}/publish`, {
publish,
});
return data;
} catch (error) {
Expand Down
6 changes: 3 additions & 3 deletions src/services/user.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import axios from "axios";
import api from "./baseUrl";

export const signup = async ({ name, email, password }) => {
try {
const { data } = await axios.post("api/v1/auth/register", {
const { data } = await api.post("api/v1/auth/register", {
name,
email,
password,
Expand All @@ -19,7 +19,7 @@ export const signup = async ({ name, email, password }) => {

export const login = async ({ email, password }) => {
try {
const { data } = await axios.post("/api/v1/auth/login", {
const { data } = await api.post("/api/v1/auth/login", {
email,
password,
});
Expand Down
33 changes: 23 additions & 10 deletions src/services/userQuiz.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import axios from "axios";
import api from "./baseUrl";
import { toast } from "react-hot-toast";

export const getQuizByIdForUser = async ({ quizId }) => {
try {
console.log("Quiz Id", quizId);

const { data } = await axios.get(`/api/v1/userQuiz/${quizId}`);
const { data } = await api.get(`/api/v1/userQuiz/${quizId}`, {
withCredentials: true,
});

// let data = undefined;
console.log("User Quiz Data : ", data);
Expand All @@ -25,11 +27,17 @@ export const getQuizByIdForUser = async ({ quizId }) => {

export const submitOneQuestion = async ({ quizId, questionId, answer }) => {
try {
const { data } = await axios.post(`/api/v1/userQuiz/submitAnswer`, {
quizId,
questionId,
answer,
});
const { data } = await api.post(
`/api/v1/userQuiz/submitAnswer`,
{
quizId,
questionId,
answer,
},
{
withCredentials: true,
}
);
// console.log("USer Quiz Data : ", data);
return data;
} catch (error) {
Expand All @@ -44,7 +52,9 @@ export const submitOneQuestion = async ({ quizId, questionId, answer }) => {

export const submitQuiz = async ({ quizId }) => {
try {
const { data } = await axios.post(`/api/v1/userQuiz/${quizId}/finishQuiz`);
const { data } = await api.post(`/api/v1/userQuiz/${quizId}/finishQuiz`, {
withCredentials: true,
});
// console.log("USer Quiz Data : ", data);
return data;
} catch (error) {
Expand All @@ -59,8 +69,11 @@ export const submitQuiz = async ({ quizId }) => {

export const getResultByIds = async ({ quizId, resultId }) => {
try {
const { data } = await axios.get(
`/api/v1/userQuiz/result/${quizId}/${resultId}`
const { data } = await api.get(
`/api/v1/userQuiz/result/${quizId}/${resultId}`,
{
withCredentials: true,
}
);
// console.log("USer Quiz Data : ", data);
return data;
Expand Down