Skip to content

Commit

Permalink
Merge branch 'dev' into ZP01/Feat/Portfolio-Landing-page-empty-state-…
Browse files Browse the repository at this point in the history
…working
  • Loading branch information
Phingaz authored Oct 22, 2023
2 parents 2104208 + e6012e2 commit e74ea87
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 22 deletions.
46 changes: 25 additions & 21 deletions components/Modals/ComplaintModal.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
// from cookies
{
/*function getAuthTokenFromCookies(cookieName: string): string | null {
function getAuthTokenFromCookies(cookieName: string): string | null {
const cookies = document.cookie;
const cookieArray = cookies.split(';');

Expand All @@ -13,36 +11,31 @@

return null;
}
*/
}

// from local storage

import { useState, useEffect } from 'react';
import { useState } from 'react';
import Modal from '@ui/Modal';
import { toast } from 'react-toastify';
import getZptValueFromLocalStorage from './tokenkey';

interface ModalProps {
isOpen: boolean;
onClose: () => void;
}
interface ComplaintModalProps extends ModalProps {
product: string;
customerID: string;
user: string;
}
// const token = getAuthTokenFromCookies('UTM_tracker');
const apiURL = 'https://zuri-cart-checkout.onrender.com/api/v1/checkout_cart/complaints';
// const token = getAuthTokenFromCookies('UTM_tracker');
const apiUrl = `https://team-mirage-super-amind2.onrender.com/api/v1/super-admin/feedback/register-complaints/`;

const ComplaintModal: React.FC<ComplaintModalProps> = ({ isOpen, onClose, product, customerID }) => {
const ComplaintModal: React.FC<ComplaintModalProps> = ({ isOpen, onClose, product, user }) => {
const [description, setDescription] = useState('');
const [error, setError] = useState<string | null>(null);

const data = { product_id: product, complaint: description };
const data = { user: user, product: product, complaint: description };
const stringifyData = JSON.stringify(data);

//auth Token
const zptValue = getZptValueFromLocalStorage();
//auth
// const authToken = `eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6ImE3YjRiOThiLWFlMzMtNGQ0Yy1hNmUzLTQ4YzY5MGQ5NDUyMyIsImZpcnN0TmFtZSI6IkJvcmRlciIsImVtYWlsIjoibW9yemV5b21sZUBndWZ1bS5jb20iLCJpYXQiOjE2OTcyNzUwMDR9.2v-dtbXuYl5J97F_S2M-vZB8lVuAnwCM1x3FJ0xOJWs`;

const handleSubmit = async (e: React.FormEvent) => {
e.preventDefault();
Expand All @@ -51,11 +44,11 @@ const ComplaintModal: React.FC<ComplaintModalProps> = ({ isOpen, onClose, produc
setError('Complaint cannot be empty');
} else {
try {
const response = await fetch(apiURL, {
const response = await fetch(apiUrl, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${zptValue}`,
// Authorization: `Bearer ${authToken}`,
},
body: stringifyData,
});
Expand All @@ -70,10 +63,19 @@ const ComplaintModal: React.FC<ComplaintModalProps> = ({ isOpen, onClose, produc
progress: undefined,
theme: 'light',
});
{
/* const res = await response.json();
console.log(res.data);
setError(''); // Clear any previous errors
onClose();
} else {
setError('Failed to submit complaint. Please try again.');
}*/
}

const res = await response.json();
console.log(res.data);
setError('');
setError(''); // Clear any previous errors
onClose();
} else {
const errorData = await response.json();
Expand All @@ -82,15 +84,17 @@ const ComplaintModal: React.FC<ComplaintModalProps> = ({ isOpen, onClose, produc
} else if (response.status === 403) {
console.error('403: 403 Forbidden - You are not authorized to perform this action');
} else if (response.status === 500) {
console.error('500: 500 something went wrong. Please try again');
console.error('500: 500 Internal Server Error - Complaint not saved. Please try again');
} else if (response.status === 401) {
console.error('401: 401 Unauthorized - Authentication required');
} else if (response.status === 422) {
console.error('422: 422 Unprocessable Entity - Invalid data submitted');
} else {
console.error('An error occurred while submitting your complaint');
}
toast.error(errorData.message, {});
toast.error(errorData.message, {
// Other error notification settings
});
}
} catch (err: any) {
console.error(err);
Expand Down
2 changes: 1 addition & 1 deletion pages/user/customer-purchase-dashboard/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ const MyPage: React.FC = () => {
isOpen={isModalOpen}
onClose={closeModal}
product={selectedOrder?.product_id || ''}
customerID={selectedOrder?.customer_id || ''}
user={selectedOrder?.customer_id || ''}
/>
{/* delete modal */}
<DeleteModal isOpen={isOpen} onClose={onClose} onDelete={onDelete} />
Expand Down

0 comments on commit e74ea87

Please sign in to comment.