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

Add subscribe/unsubscribe button on UI #156

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

NenadJeckovic
Copy link
Contributor

Added subscription buttons on book details page with tests.

initTest(SCREEN_WIDTH);
jest
.spyOn(Router, "useParams")
.mockReturnValue({ bookId: UNSUBSCRIBED_BOOK });
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Name shouldn't be unsubscribed book, as we don't have that status in our system

initTest(SCREEN_WIDTH);
jest
.spyOn(Router, "useParams")
.mockReturnValue({ bookId: SUBSCRIBED_BOOK });
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also here, in this moment I suppose we are not subscribed?

Comment on lines 46 to 47
export const getSubscription = async (bookId: number) =>
client.get(`/inventory/subscriptions/${bookId}`);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have mechanism in gateway of fetching all data for book details page. Getting subscription information should be done there, and then we wouldn't have getSubscription on our client

export const getSubscription = async (bookId: number) =>
client.get(`/inventory/subscriptions/${bookId}`);

export const postSubscribe = async (bookId: number) =>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

postSubscription

export const postSubscribe = async (bookId: number) =>
client.post(`/inventory/subscriptions/subscribe/${bookId}`);

export const postUnsubscribe = async (bookId: number) =>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should discuss is this candidate for http POST method or DELETE

import { useEffect, useState } from "react";
import * as bookService from "../services/BookService";

const useSubscribe = (bookId: number) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

useBookSubscription

const { showSuccessScreen } = useSuccessScreenContext();

const subscribeClick = () => {
subscribe().then(() => {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens when subscribe or unsubscribe api fails? We should think of showing error message for the user.

@NenadJeckovic NenadJeckovic linked an issue Mar 28, 2024 that may be closed by this pull request
Copy link
Contributor

@dusanpetrovicpd dusanpetrovicpd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! We won't merge it until this functionality is available on backend

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add subscribe/unsubscribe button on UI
3 participants