Skip to content

Commit

Permalink
order submit with unauthorized user temporary fix
Browse files Browse the repository at this point in the history
  • Loading branch information
ShinokiX3 committed Sep 6, 2023
1 parent 500132a commit d381265
Show file tree
Hide file tree
Showing 8 changed files with 14 additions and 21 deletions.
1 change: 0 additions & 1 deletion src/components/layout/auth/LoginForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ const LoginForm: React.FC<ILoginForm> = ({ children }) => {
setLoading(true);

const resp = await AuthService.login({ email, password });
console.log(resp);

if (resp?.token) {
setStatus('success');
Expand Down
2 changes: 1 addition & 1 deletion src/components/screen/home/Promo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ const Promo = () => {
width={0}
height={0}
style={{
width: '70%',
width: '100%',
height: 'auto',
maxHeight: '300px',
objectFit: 'cover',
Expand Down
15 changes: 9 additions & 6 deletions src/components/ui/checkout/Eventually.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ const Eventually = () => {

const submit = async () => {
setLoading(true);

const data = {
name: order.name,
lastname: order.lastname,
Expand All @@ -70,19 +71,21 @@ const Eventually = () => {
products: products,
};

const createdOrder = await UserService.createOrder(data, { id: user._id });
const createdOrder = user._id
? await UserService.createOrder(data, { id: user._id })
: await UserService.createOrder(data, '');

if (createdOrder.order)
if (createdOrder.order || createdOrder.date)
router.push(
`checkout/success?id=${createdOrder.order._id}&total=${createdOrder.order.total}`
`checkout/success?id=${
createdOrder.order?._id || createdOrder._id
}&total=${createdOrder.order?.total || createdOrder.total}`
);

setLoading(false);
};

if (loading) {
return <Spinner />;
}
if (loading) return <Spinner />;

return (
<Wrapper>
Expand Down
1 change: 0 additions & 1 deletion src/components/ui/checkout/Order.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ const ItemWrapper = styled.div`

const Order = () => {
const { items } = useTypedSelector((state) => state.cart);
console.log(items);

return (
<Wrapper>
Expand Down
1 change: 0 additions & 1 deletion src/components/ui/checkout/delivery/City.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ const City = () => {
if (debouncedValue) {
setLoading(true);
const response = await NovaPoshta.searchByTerm(value);
console.log(response);

if (response.data.length > 0) {
setCities(response.data);
Expand Down
7 changes: 2 additions & 5 deletions src/components/ui/product/description/Description.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,6 @@ const Wrapper = styled.div`
// TODO: typed this function

const Description: React.FC<IDescripton> = ({ data }) => {
console.log(data);

const { items } = useTypedSelector((state) => state.cart);
const user = useTypedSelector((state) => state.user.user);
const { addToCart, pushFavourite, removeFavourite } = useActions();
Expand All @@ -76,9 +74,8 @@ const Description: React.FC<IDescripton> = ({ data }) => {

const handleToCart = () => {
// TODO: Desctructuring object
// TODO: Where can i get price?
// TODO: Where can we get price?
const { _id, title, picture, cost, discount } = data.product;
console.log(data);

addToCart({
asin: _id,
Expand All @@ -92,7 +89,7 @@ const Description: React.FC<IDescripton> = ({ data }) => {
};

const handleFavourites = async () => {
if (JSON.stringify(user) === '{}') console.log('Error');
if (JSON.stringify(user) === '{}') console.log('Something wrong...');

if (user.favourites?.some((item) => item === data.product._id)) {
const response = await UserService.removeFavourite(data.product._id);
Expand Down
6 changes: 1 addition & 5 deletions src/components/ui/search/Search.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@ const SearchHandling = ({
if (loading) return <Spinner />;
if (data.length === 0) return <Empty />;

console.log(data);

return (
<Wrapper>
{data.map((item) => (
Expand Down Expand Up @@ -90,7 +88,7 @@ const Search = ({ styles }: { styles?: Object }) => {
else setSearchResults(products);

setLoading(false);
} else console.log('declined');
}
})();
}, [debouncedValue]);

Expand All @@ -115,6 +113,4 @@ const Search = ({ styles }: { styles?: Object }) => {
);
};

// treeData={searchResults}

export default Search;
2 changes: 1 addition & 1 deletion src/services/Server/SeverUser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const USER = '/users';
export const UserService = {
// Order

async createOrder(order: any, user: any) {
async createOrder(order: any, user: string | { id: string }) {
try {
const { data } = await serverApiClient.post<any>(`${USER}/order/create`, {
order,
Expand Down

0 comments on commit d381265

Please sign in to comment.