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

Updated portfolio api base url and fixed issues with settings page #1516

Merged
merged 2 commits into from
Dec 11, 2023
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
6 changes: 3 additions & 3 deletions components/Modals/interest-modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { checkObjectProperties } from '@modules/portfolio/functions/checkObjectP
import Loader from '@ui/Loader';
import { AiOutlineClose, AiOutlineCloseCircle, AiOutlinePlus } from 'react-icons/ai';

const endpoint = 'https://hng6-r5y3.onrender.com';
const endpoint = `${process.env.NEXT_PUBLIC_BACKEND_ENDPOINT_URL}/portfolio`;

type interestModalProps = {
onCloseModal: () => void;
Expand Down Expand Up @@ -94,7 +94,7 @@ const InterestModal = ({ isOpen, onCloseModal, onSaveModal, userId }: interestMo
userId: userId,
};
axios
.post(`${endpoint}/api/v1/interests`, data)
.post(`${endpoint}/interests`, data)
.then((res) => {
setLoading(false);
notify({
Expand Down Expand Up @@ -154,7 +154,7 @@ const InterestModal = ({ isOpen, onCloseModal, onSaveModal, userId }: interestMo
const getAllInterests = () => {
setInitialLoading(true);
axios
.get(`${endpoint}/api/v1/interests/${userId}`)
.get(`${endpoint}/interests/${userId}`)
.then((res) => {
setInitialLoading(false);
const interestsArray: string[] = res.data?.interestArray;
Expand Down
10 changes: 5 additions & 5 deletions components/Modals/language-modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ type languageModalProps = {
userId: string;
};

const endpoint = 'https://hng6-r5y3.onrender.com';
const endpoint = (`${process.env.NEXT_PUBLIC_BACKEND_ENDPOINT_URL}/portfolio`) as string;
const programmingLanguages = [
'JavaScript',
'TypeScript',
Expand Down Expand Up @@ -101,7 +101,7 @@ const LanguageModal = ({ isOpen, onCloseModal, onSaveModal, userId }: languageMo
};

const handleDelete = async (params: any) => {
const data = await fetch(`https://hng6-r5y3.onrender.com/api/v1/languages`, {
const data = await fetch(`${process.env.NEXT_PUBLIC_BACKEND_ENDPOINT_URL}/portfolio/languages`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
Expand Down Expand Up @@ -141,7 +141,7 @@ const LanguageModal = ({ isOpen, onCloseModal, onSaveModal, userId }: languageMo
sectionId: 5,
};
axios
.post(`${endpoint}/api/v1/languages`, data)
.post(`${endpoint}/languages`, data)
.then(async (res) => {
setLoading(false);
notify({
Expand All @@ -151,7 +151,7 @@ const LanguageModal = ({ isOpen, onCloseModal, onSaveModal, userId }: languageMo
type: 'success',
});
setValues([]);
await fetch(`${endpoint}/api/v1/getPorfolio/${userId}`);
await fetch(`${endpoint}/getPorfolio/${userId}`);
onSaveModal();
})
.catch((err) => {
Expand All @@ -169,7 +169,7 @@ const LanguageModal = ({ isOpen, onCloseModal, onSaveModal, userId }: languageMo
const getAllLanguages = () => {
setInitialLoading(true);
axios
.get(`${endpoint}/api/v1/languages/${userId}`)
.get(`${endpoint}/languages/${userId}`)
.then((res) => {
if (res.data.data !== null) {
setInitialLoading(false);
Expand Down
1 change: 0 additions & 1 deletion components/Navbars/TopBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,6 @@ function TopBar(props: { activePage: string; showDashBorad: boolean }) {
setToggle(false);
}
if (notificationsRef.current && !notificationsRef.current.contains(targetNode)) {
console.log(notificationsRef.current);
setNotificationMenu(false);
}
}
Expand Down
4 changes: 2 additions & 2 deletions context/PortfolioLandingContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ const Portfolio = createContext<PortfolioContext>({
export function PortfolioCtxProvider(props: { children: any }) {
const queryClient = useQueryClient();
const router = useRouter();
const portfolioUrl = `https://hng6-r5y3.onrender.com/api/v1/portfolio`;
const portfolioUrl = `${process.env.NEXT_PUBLIC_BACKEND_ENDPOINT_URL}/portfolio/portfolio`;
const { auth } = useAuth();
const [userId, setUserId] = useState('');
const [slug, setSlug] = useState('');
Expand Down Expand Up @@ -272,7 +272,7 @@ export function PortfolioCtxProvider(props: { children: any }) {
formData.append('images', coverImage as string | Blob);
formData.append('userId', userId);

const response = await fetch('https://hng6-r5y3.onrender.com/api/v1/profile/cover/upload', {
const response = await fetch(`${process.env.NEXT_PUBLIC_BACKEND_ENDPOINT_URL}/portfolio/profile/cover/upload`, {
method: 'POST',
body: formData,
});
Expand Down
3 changes: 2 additions & 1 deletion http/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import axios from 'axios';

const AUTH_HTTP_URL = 'https://zuri-auth.up.railway.app/api/auth/api/auth';
const AUTH_HTTP_URL_2 = 'https://staging.zuri.team/api/auth/api';
const _AUTH_HTTP_URL = 'https://zuri-auth.up.railway.app/api/auth/api';

const $http = axios.create({
baseURL: AUTH_HTTP_URL,
Expand All @@ -11,7 +12,7 @@ const $http = axios.create({
});

const $http_2 = axios.create({
baseURL: AUTH_HTTP_URL_2,
baseURL: _AUTH_HTTP_URL,
timeout: 30000,
headers: {
'Content-Type': 'application/json; charset=UTF-8',
Expand Down
2 changes: 1 addition & 1 deletion http/axios.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const $http = axios.create({
headers: {
'Content-Type': 'application/json',
credentials: 'include',
// 'Access-Control-Allow-Origin': '*',
'Access-Control-Allow-Origin': '*',
},
// withCredentials: false,
});
Expand Down
4 changes: 2 additions & 2 deletions http/checkout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import axios from 'axios';


// export const CART_ENDPOINT = "https://zuri-cart-checkout.onrender.com/api/v1/checkout_cart"
export const CART_ENDPOINT = "http://localhost:8000/api/v1/checkout_cart"
export const CART_ENDPOINT = process.env.NEXT_PUBLIC_BACKEND_ENDPOINT_URL + "/checkout";
export const STAGING_URL = process.env.NEXT_PUBLIC_APP_STAGING_URL || 'https://staging.zuri.team';
export const RECENTLY_VIEWED_ENDPOINT = 'https://staging.zuri.team/api/marketplace/v1/recently-viewed';

Expand Down Expand Up @@ -188,7 +188,7 @@ export const getRecentlyViewedProducts = async (token: string) => {
};

export const getRecommendedProducts = async () => {
const apiUrl = 'https://coral-app-8bk8j.ondigitalocean.app/api/marketplace/recommendations';
const apiUrl = 'https://coral-app-8bk8j.ondigitalocean.app/api/marketplace/v1/recommendations';
try {
const response = await axios.get(apiUrl);
return response.data.data;
Expand Down
2 changes: 1 addition & 1 deletion modules/explore/explorePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ const HomePage = () => {
const { data, isLoading } = useQuery<UserInfo>({
queryKey: ['profile', deBounce, filters, pageNumber],
queryFn: () => fetchUsers(searchQuery),
staleTime: 60000,
// staleTime: 60000,
});

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export default function ProductWeThoughtMightInterestYou({ id }: any) {
const { setCartCountNav, cartCount } = useCart();
const [cartLoading, setCartLoading] = useState<boolean>(true);

const url = `https://coral-app-8bk8j.ondigitalocean.app/api/marketplace/similar_products/${id}/`;
const url = `https://coral-app-8bk8j.ondigitalocean.app/api/marketplace/v1/similar_products/${id}/`;
useEffect(() => {
fetch(url)
.then((res) => res.json())
Expand All @@ -30,7 +30,7 @@ export default function ProductWeThoughtMightInterestYou({ id }: any) {
}, [url]);

const addToCart = async (ids: string) => {
const apiUrl = `${CART_ENDPOINT}/api/carts`;
const apiUrl = `${CART_ENDPOINT}/carts`;
if (auth?.token) {
try {
const response = await axios.post(
Expand Down
4 changes: 2 additions & 2 deletions modules/marketplace/http/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import axios from 'axios';

// export let API_URI = 'https://coral-app-8bk8j.ondigitalocean.app/api/marketplace/v1';
export let API_URI = 'https://staging.zuri.team/api/marketplace/v1';
export let API_URI = 'https://coral-app-8bk8j.ondigitalocean.app/api/marketplace/v1';
// export let API_URI = 'https://staging.zuri.team/api/marketplace/v1';

const http = axios.create({
baseURL: API_URI,
Expand Down
10 changes: 5 additions & 5 deletions modules/portfolio/component/about/about.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ const PortfolioAbout: React.FC<aboutModalProps> = ({ onCloseModal, onSaveModal,
const [create, setCreate] = useState(false);

// POST ABOUT VALUE TO DATABASE
const API_BASE_URL = 'https://hng6-r5y3.onrender.com';
const API_BASE_URL = (`${process.env.NEXT_PUBLIC_BACKEND_ENDPOINT_URL}/portfolio`) as string;
const createResponse = async () => {
try {
const axiosConfig = {
method: 'post',
url: `${API_BASE_URL}/api/v1/about/${userId}`,
url: `${API_BASE_URL}/about/${userId}`,
data: bio,
};

Expand Down Expand Up @@ -79,7 +79,7 @@ const PortfolioAbout: React.FC<aboutModalProps> = ({ onCloseModal, onSaveModal,
try {
const axiosConfig = {
method: 'get',
url: `${API_BASE_URL}/api/v1/about/${userId}`,
url: `${API_BASE_URL}/about/${userId}`,
};

const response = await axios(axiosConfig);
Expand Down Expand Up @@ -115,7 +115,7 @@ const PortfolioAbout: React.FC<aboutModalProps> = ({ onCloseModal, onSaveModal,
try {
const axiosConfig = {
method: 'put',
url: `${API_BASE_URL}/api/v1/about/${id}`,
url: `${API_BASE_URL}/about/${id}`,
data: bio,
};

Expand Down Expand Up @@ -179,7 +179,7 @@ const PortfolioAbout: React.FC<aboutModalProps> = ({ onCloseModal, onSaveModal,
try {
const axiosConfig = {
method: 'delete',
url: `${API_BASE_URL}/api/v1/about/${id}`,
url: `${API_BASE_URL}/about/${id}`,
};

const response = await axios(axiosConfig);
Expand Down
12 changes: 6 additions & 6 deletions modules/portfolio/component/awards-modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ const initialContextValue: Context = {
error: '',
setIsLoading: () => {},
isLoading: false,
baseURL: 'https://hng6-r5y3.onrender.com', // Add baseURL with a default value
baseURL: (`${process.env.NEXT_PUBLIC_BACKEND_ENDPOINT_URL}/portfolio`) as string, // Add baseURL with a default value
setBaseURL: () => {}, // Add setter for baseURL
};

Expand All @@ -62,7 +62,7 @@ const Awards = ({ isOpen, onCloseModal }: awardsModalProps) => {
url: '',
description: '',
});
const [baseURL, setBaseURL] = useState('https://hng6-r5y3.onrender.com');
const [baseURL, setBaseURL] = useState(`${process.env.NEXT_PUBLIC_BACKEND_ENDPOINT_URL}/portfolio`);
const [isModalOpen, setIsModalOpen] = useState(false);
const [urlError, setUrlError] = useState('');
const [error, setError] = useState('');
Expand All @@ -82,7 +82,7 @@ const Awards = ({ isOpen, onCloseModal }: awardsModalProps) => {

try {
setIsLoading(true);
const response = await fetch(`${baseURL}/api/v1/awards/${userId}`, {
const response = await fetch(`${baseURL}/awards/${userId}`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
Expand Down Expand Up @@ -365,7 +365,7 @@ const AwardList: React.FC<AwardListProps> = () => {
const fetchAwards = async () => {
try {
setIsLoading(true);
const response = await fetch(`${baseURL}/api/v1/awards`);
const response = await fetch(`${baseURL}/awards`);
setIsLoading(false);
const status = response.status;

Expand Down Expand Up @@ -446,7 +446,7 @@ const AwardItem: React.FC<AwardItemProps> = ({ award }) => {
// Send a PUT request to update the award
try {
setEditLoading(true);
const response = await fetch(`${baseURL}/api/v1/awards/${id}`, {
const response = await fetch(`${baseURL}/awards/${id}`, {
method: 'PUT',
headers: {
'Content-Type': 'application/json',
Expand Down Expand Up @@ -513,7 +513,7 @@ const AwardItem: React.FC<AwardItemProps> = ({ award }) => {

try {
setDeleteLoading(true);
const response = await fetch(`${baseURL}/api/v1/awards/${id}`, {
const response = await fetch(`${baseURL}/awards/${id}`, {
method: 'DELETE',
});
const status = response.status;
Expand Down
4 changes: 2 additions & 2 deletions modules/portfolio/component/certification-modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ const initialContextValue: Context = {
error: '',
setIsLoading: () => {},
isLoading: false,
baseURL: 'https://hng6-r5y3.onrender.com', // Add baseURL with a default value
baseURL: (`${process.env.NEXT_PUBLIC_BACKEND_ENDPOINT_URL}/portfolio`) as string, // Add baseURL with a default value
setBaseURL: () => {}, // Add setter for baseURL
};

Expand All @@ -62,7 +62,7 @@ const Certifications = ({ isOpen, onCloseModal }: certificationModalProps) => {
url: '',
description: '',
});
const [baseURL, setBaseURL] = useState('https://hng6-r5y3.onrender.com');
const [baseURL, setBaseURL] = useState(`${process.env.NEXT_PUBLIC_BACKEND_ENDPOINT_URL}/portfolio`);
const [isModalOpen, setIsModalOpen] = useState(false);
const [urlError, setUrlError] = useState('');
const [error, setError] = useState('');
Expand Down
8 changes: 4 additions & 4 deletions modules/portfolio/component/contact-modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ function ContactModal({ isOpen, onCloseModal, onSaveModal, userId }: contactModa
user_id: userId, // Ensure you have the userId available
}));

sendArrayOfObjects(data, 'https://hng6-r5y3.onrender.com/api/v1/contacts')
sendArrayOfObjects(data, `${process.env.NEXT_PUBLIC_BACKEND_ENDPOINT_URL}/portfolio/contacts`)
.then((response: any) => {
setLoading(false);
notify({
Expand Down Expand Up @@ -128,7 +128,7 @@ function ContactModal({ isOpen, onCloseModal, onSaveModal, userId }: contactModa
console.log('delete clicked');
const id = 5;
try {
const res = await fetch(`https://hng6-r5y3.onrender.com/api/v1/contacts/${id}`, {
const res = await fetch(`${process.env.NEXT_PUBLIC_BACKEND_ENDPOINT_URL}/portfolio/contacts/${id}`, {
method: 'DELETE',
headers: {
'Content-Type': 'application/json',
Expand All @@ -145,7 +145,7 @@ function ContactModal({ isOpen, onCloseModal, onSaveModal, userId }: contactModa

const getSocialsAvailable = async () => {
try {
const response = await axios.get(`https://hng6-r5y3.onrender.com/api/v1/socials`);
const response = await axios.get(`${process.env.NEXT_PUBLIC_BACKEND_ENDPOINT_URL}/portfolio/socials`);
const data = await response.data;
console.log('getSocialsAvailable', data);
setAvailableSocials(data?.data);
Expand All @@ -164,7 +164,7 @@ function ContactModal({ isOpen, onCloseModal, onSaveModal, userId }: contactModa

const getAllSocials = async () => {
try {
const response = await axios.get(`https://hng6-r5y3.onrender.com/api/v1/contacts/${userId}`);
const response = await axios.get(`${process.env.NEXT_PUBLIC_BACKEND_ENDPOINT_URL}/portfolio/contacts/${userId}`);
const data = await response.data;
console.log('responseData', data);
} catch (error) {
Expand Down
2 changes: 1 addition & 1 deletion modules/portfolio/component/modals/apiService.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import axios from 'axios';

const BASE_URL = 'https://hng6-r5y3.onrender.com/api/v1';
const BASE_URL = `${process.env.NEXT_PUBLIC_BACKEND_ENDPOINT_URL}/portfolio/`;

export const updateProfileDetails = async (userId, newProfileDetails) => {
try {
Expand Down
19 changes: 12 additions & 7 deletions modules/portfolio/component/modals/edit-profile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,14 @@ const EditProfile = () => {

useEffect(() => {


console.log("Logging before fetch")
const fetchData = async () => {
try {
setIsLoading(true);
const response = await fetch(`https://hng6-r5y3.onrender.com/api/v1/users/${userId}`);
console.log('Logging this one');
const response = await fetch(`${process.env.NEXT_PUBLIC_BACKEND_ENDPOINT_URL}/portfolio/users/${userId}`);
console.log('after logging');

const userData = await response.json();


Expand All @@ -61,7 +64,7 @@ const EditProfile = () => {

const getTracks = async () => {
try {
const response = await fetch('https://hng6-r5y3.onrender.com/api/v1/tracks');
const response = await fetch(`${process.env.NEXT_PUBLIC_BACKEND_ENDPOINT_URL}/portfolio/tracks`);
const data = await response.json();
return data.data;
} catch (error: any) {
Expand Down Expand Up @@ -96,7 +99,9 @@ const EditProfile = () => {
matchingTrack = availableTracks.find((track: any) => track.track === selectedTrack);
if (matchingTrack) {
setIsLoading(true);
const response = await fetch(`https://hng6-r5y3.onrender.com/api/v1/users/${userId}`, {
console.log("Logging second one");
const response = await fetch(`${process.env.NEXT_PUBLIC_BACKEND_ENDPOINT_URL}/portfolio/users/${userId}`,
{
method: 'PUT',
headers: {
'Content-Type': 'application/json',
Expand Down Expand Up @@ -131,7 +136,7 @@ const EditProfile = () => {
const formData = new FormData();
formData.append('images', coverImage as string | Blob);
formData.append('userId', userId);
const response = await fetch('https://hng6-r5y3.onrender.com/api/v1/profile/image/upload', {
const response = await fetch(`${process.env.NEXT_PUBLIC_BACKEND_ENDPOINT_URL}/portfolio/profile/image/upload`, {
method: 'POST',
body: formData,
});
Expand Down Expand Up @@ -253,14 +258,14 @@ const EditProfile = () => {
</label>
{/* <Badges name={badgeData.name} badgeImage={badgeData.badgeImage} /> */}
</div>
​ ​

<CountryCityDropdown
setSelectedCountry={setSelectedCountry}
setSelectedCity={setSelectedCity}
selectedCountry={selectedCountry}
selectedCity={selectedCity}
/>

<div className="w-full flex md:flex-row gap-4 justify-between mt-6">
<div className="w-full md:w-[47%]">
<Button
Expand Down
Loading