11import React , { useState , useEffect , useRef } from 'react'
2- import axios from 'axios'
3- import { apiURL } from '../config.json'
42import { trackPromise , usePromiseTracker } from 'react-promise-tracker'
53import { Helmet } from 'react-helmet'
64import { navigate } from '@reach/router'
@@ -13,6 +11,9 @@ import Dropdown from '../components/Dropdown'
1311import UserProfile from '../components/UserProfile'
1412import Lists from '../utils/Lists'
1513
14+ import userStory from '../services/user_story'
15+ import User from '../services/user'
16+
1617const Profile = ( props ) => {
1718 const { profileId } = props
1819 const [ stories , setStories ] = useState ( [ ] )
@@ -35,19 +36,7 @@ const Profile = (props) => {
3536
3637 useEffect ( ( ) => {
3738 const fetchProducts = async ( ) => {
38- const response = await axios . post (
39- `${ apiURL } /graphql` ,
40- {
41- query : `query {
42- products {
43- Name
44- }
45- }`
46- } ,
47- {
48- withCredentials : true
49- }
50- )
39+ const response = await userStory . getProducts ( )
5140 setProducts (
5241 response . data . data . products . map ( ( ele ) => {
5342 return ele . Name
@@ -60,9 +49,7 @@ const Profile = (props) => {
6049
6150 useEffect ( ( ) => {
6251 const fetchCategories = async ( ) => {
63- const response = await axios . post ( `${ apiURL } /graphql` , {
64- query : '{ __type(name: "ENUM_USERSTORY_CATEGORY") {enumValues {name}}}'
65- } )
52+ const response = await userStory . getCategories ( )
6653
6754 setCategories (
6855 response . data . data . __type . enumValues . map ( ( ele ) => {
@@ -76,30 +63,7 @@ const Profile = (props) => {
7663
7764 useEffect ( ( ) => {
7865 const fetchUserInfo = async ( ) => {
79- const response = await axios . post (
80- `${ apiURL } /graphql` ,
81- {
82- query : `query {
83- user(id: "${ profileId } ") {
84- profilePicture {
85- url
86- }
87- Name
88- Bio
89- username
90- Company
91- Profession
92- email
93- LinkedIn
94- Twitter
95- }
96- }
97- `
98- } ,
99- {
100- withCredentials : true
101- }
102- )
66+ const response = await User . getInfo ( profileId )
10367 setUser ( response . data . data . user )
10468 }
10569 if ( profileId ) {
@@ -109,40 +73,7 @@ const Profile = (props) => {
10973
11074 useEffect ( ( ) => {
11175 const fetchMyStories = async ( ) => {
112- const response = await axios . post (
113- `${ apiURL } /graphql` ,
114- {
115- query : `query {
116- user(id: "${ profileId } ") {
117- user_stories {
118- id
119- Title
120- Description
121- user_story_status {
122- Status
123- }
124- followers {
125- username
126- }
127- product {
128- Name
129- }
130- author {
131- id
132- username
133- }
134- user_story_comments {
135- Comments
136- }
137- Category
138- }
139- }
140- }`
141- } ,
142- {
143- withCredentials : true
144- }
145- )
76+ const response = await User . getUserStoriesByUser ( profileId )
14677 setStories ( response . data . data . user . user_stories )
14778 }
14879 trackPromise ( fetchMyStories ( ) )
0 commit comments