Skip to content

Commit

Permalink
my chnages
Browse files Browse the repository at this point in the history
  • Loading branch information
zintarh committed Apr 6, 2022
1 parent c977d1c commit 676fcbf
Show file tree
Hide file tree
Showing 6 changed files with 102 additions and 58 deletions.
14 changes: 11 additions & 3 deletions src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,28 @@ function App() {
const { isAuth } = useSelector((state) => state.user);
const token = localStorage.token;
var decoded = jwt_decode(token);
console.log(decoded)

return (
<>
<Router>
<Routes>


<Route path="/" element={<HomePage />} />



<Route path="/auth" element={<SignUpAndSignUp />} />
<Route path="/auth" element={

<SignUpAndSignUp />


} />

<Route
path="/dashboard"
element={
<PrivateRoute isAuthenticated={true}>
<PrivateRoute isAuthenticated={decoded.isLoggedIn}>
<UserDashboard />
</PrivateRoute>
}
Expand Down
File renamed without changes
120 changes: 75 additions & 45 deletions src/pages/Dashboard.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ import * as Yup from "yup";

import { useNavigate } from "react-router-dom";

import logo from '../assets/logo.png'
import logo from "../assets/logo.png";

import glogo from "../assets/open-global.png";

const UserDashboard = () => {
toast.configure();
Expand All @@ -27,58 +29,85 @@ const UserDashboard = () => {

const { clearState } = feedReducer.actions;

const { isLoading, isError, isSuccess, errorMessage, feeds } = useSelector(
(state) => state.feed
);
const {
isLoading,
isError,
isSuccessCreate,
feeds,
} = useSelector((state) => state.feed);
const [showModal, setShowModal] = useState(false);

const [mediaFile, setMediaFile] = useState("");

const dispatch = useDispatch();
const { register, errors, handleSubmit } = useForm();

const onSubmit = async (data) => {
const formdata = {
feed_title: data.feed_title,
feed_description: data.feed_description,
feed_media: mediaFile,
tag: data.tag,
const onSubmit = async (request) => {
const data = new FormData();
data.append("file", mediaFile);
data.append("upload_preset", "nhubnigeria");
data.append("cloud_name", "nhubnacademy");
const response = await fetch(
" https://api.cloudinary.com/v1_1/nhubnacademy/image/upload",
{
method: "post",
body: data,
}
);

let result = await response.json();

const spoons = {
feed_title: request.feed_title,
feed_description: request.feed_description,
tag: request.tag,
feed_media: result.secure_url,
};

await dispatch(createFeed(spoons));

await dispatch(clearState());


console.log(formdata);
};

await dispatch(createFeed(formdata));
useEffect(() => {
}, []);

console.log(isSuccess);

if (isSuccess) {
toast.success("Feed was created successfully!");
setShowModal(false);
}
};

useEffect(() => {

dispatch(getFeeds());

if (isSuccessCreate) {
console.log("sjjshshshjshjs")
toast.success("Feed was created successfully!");
setShowModal(false);
dispatch(getFeeds());
dispatch(clearState());

}
if (isError) {
toast.error("There was an error, Try again later!");
dispatch(clearState());
}
}, [isSuccess, isError]);
}, [isError, isSuccessCreate]);

return (
<div className="wrapper">
<header>
<nav className=" ">
<div className="first-nav flex justify-between mx-48 py-4 bg-white">
<div className="logo">
<img
class="block lg:hidden h-8 w-auto"
src="https://tailwindui.com/img/logos/workflow-mark-indigo-500.svg"
alt="Workflow"
/>

<h1 className="font-extrabold uppercase text-secondary text-2xl">
open<span className="text-primary">Eye</span>
<div className="logo items-center flex ">
<img class="block h-8 w-auto mr-2" src={glogo} alt="Workflow" />
<img class="block w-8 h-8 " src={logo} alt="Workflow" />

<h1 className="font-extrabold text-secondary text-xl">
pen
<span className="text-primary text-center mt-auto">
Governmnet Partnership
</span>
</h1>
</div>

Expand All @@ -100,25 +129,25 @@ const UserDashboard = () => {

<a
href="#"
class="text-white rounded-lg text-sm font-semibold hover:text-secondary px-2 py-2 rounded-one "
class="text-white rounded-lg text-sm font-semibold hover:text-secondary px-2 py-2 "
>
<i class="fa-solid fa-bell w-10 fa-4x text-primary text-sm w- text-center mx-auto py-2 px-3"></i>
<i class="fa-solid fa-bell w-10 fa-3x text-primary text-sm w- text-center mx-auto py-2 px-3"></i>
</a>

<a
href="#"
class=" text-primary rounded-lg pt-4 text-md font-semibold hover:text-secondary "
onClick={() => setShowModal(true)}
>
<i class="fa-solid fa-plus pr-2 text-primary text-sm w- text-center mx-auto "></i>
<i class="fa-solid fa-plus pr-2 fa-3x text-primary text-sm w- text-center mx-auto "></i>
Create Feed
</a>
</div>
</div>
</div>
</nav>

<div className="content pt-20 mx-10">
<div className="content pt-20 mx-40">
{isLoading ? (
<div className="spiner w-1/4 mx-auto py-40">
<svg
Expand All @@ -139,21 +168,23 @@ const UserDashboard = () => {
</svg>
</div>
) : (
<div class="p-10 grid grid-cols-1 sm:grid-cols-1 md:grid-cols-2 lg:grid-cols-2 xl:grid-cols-3 gap-10">
<div class="p-10 grid grid-cols-1 sm:grid-cols-1 md:grid-cols-2 lg:grid-cols-2 xl:grid-cols-3 gap-6">
{feeds == null ? (
<h1>No feeds</h1>
<h1 className="text-xl uppercase text-center text-gray-700 ">
No feeds or internet, please refresh
</h1>
) : (
feeds.map((feed) => (
<div className=" ">
{
<div
className=" h-48 text-center rounded-sm "
style={{ backgroundImage: 'url("https://media.istockphoto.com/photos/dreamy-cherry-blossoms-picture-id1128573396?k=20&m=1128573396&s=170667a&w=0&h=4uEEgRdNnMcuFV-WgrAPS8pULpYCbyWm5M5IaZRxCWY=")' }}
title="Mountain"
></div>
className=" h-48 text-center rounded-sm "
style={{ backgroundImage: `url(${feed.feed_media})` }}
title="Mountain"
></div>
}
<div className=" bg-white py-4 shadow-xl rounded-sm p-4 flex flex-col justify-between leading-normal">
<div className="mb-4">


<p className="text-sm text-gray-600 flex items-center">
<svg
className="fill-current text-gray-500 w-3 h-3 mr-2"
Expand All @@ -163,13 +194,12 @@ const UserDashboard = () => {
<path d="M4 8V6a6 6 0 1 1 12 0v2h1a2 2 0 0 1 2 2v8a2 2 0 0 1-2 2H3a2 2 0 0 1-2-2v-8c0-1.1.9-2 2-2h1zm5 6.73V17h2v-2.27a2 2 0 1 0-2 0zM7 6v2h6V6a3 3 0 0 0-6 0z" />
</svg>
{feed.tag}

</p>
<div className="text-primary font-bold text-xl mb-2">
{feed.feed_title}
{feed.feed_title}
</div>
<p className="text-gray-700 text-sm">
{feed.feed_description}
<p className="text-gray-700 text-sm w-2/4">
{feed.feed_description}
</p>
</div>
<div className="flex items-center">
Expand All @@ -179,7 +209,7 @@ const UserDashboard = () => {
/>
<div className="text-sm">
<p className="text-gray-900 leading-none">
ogplateau
ogplateau
</p>
<p className="text-gray-600 ">{feed.createdAt}</p>
</div>
Expand Down
8 changes: 6 additions & 2 deletions src/redux/auth/auth-comp.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export const loginUser = createAsyncThunk(

export const registerUser = createAsyncThunk(
"users/register",
async ({ email, password }, thunkAPI) => {
async ({ first_name, last_name, email, phone , gender, password2 }, thunkAPI) => {
try {
const response = await fetch(
baseurl+ "/user/register",
Expand All @@ -50,8 +50,12 @@ export const registerUser = createAsyncThunk(
"Content-Type": "application/json",
},
body: JSON.stringify({
first_name,
last_name,
email,
password,
phone,
gender,
password2
}),
}
)
Expand Down
11 changes: 6 additions & 5 deletions src/redux/feed/feed-comp.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,16 @@ const config = {
};

export const createFeed = createAsyncThunk(
"users/feed",
"users/createfeed",
async ({ feed_title, feed_description, tag, feed_media }, thunkAPI) => {
try {
console.log(token);
console.log("sjjksjks");
const response = await fetch(baseurl + "/feed", {
method: "POST",
headers: {
Accept: "application/json",
"content-type": "application/json",

Authorization: `Bearer ${token}`,
},
body: JSON.stringify({
Expand All @@ -30,9 +31,9 @@ export const createFeed = createAsyncThunk(
}),
});
let data = await response.json();
console.log("response", data);
console.log("response", data.newFeed);
if (data.success) {
return data;
return data.newFeed;
} else {
return thunkAPI.rejectWithValue(data);
}
Expand All @@ -47,7 +48,7 @@ export const createFeed = createAsyncThunk(


export const getFeeds = createAsyncThunk(
"users/feed",
"users/getfeeds",
async ( thunkAPI) => {
try {
const response = await fetch(baseurl + "/feed", {
Expand Down
7 changes: 4 additions & 3 deletions src/redux/feed/feedSlice.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const initialState = {
feeds: null,
isLoading: false,
isSuccess: false,
isSuccessCreate: false,
isError: false,
errorMessage: "",

Expand All @@ -23,11 +24,11 @@ const initialState = {
[createFeed.pending]: (state, { payload }) => {
state.isLoading = true;
},
[createFeed.fulfilled]: (state, { }) => {
[createFeed.fulfilled]: (state, { payload }) => {
console.log("hey law")
state.isError = false
state.isLoading = false;
state.isSuccess = true;
return state;
state.isSuccessCreate = true;
},
[createFeed.rejected]: (state, { payload }) => {
console.log('payload', payload);
Expand Down

0 comments on commit 676fcbf

Please sign in to comment.