-
Notifications
You must be signed in to change notification settings - Fork 0
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
base: main
Are you sure you want to change the base?
Add subscribe/unsubscribe button on UI #156
Conversation
initTest(SCREEN_WIDTH); | ||
jest | ||
.spyOn(Router, "useParams") | ||
.mockReturnValue({ bookId: UNSUBSCRIBED_BOOK }); |
There was a problem hiding this comment.
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 }); |
There was a problem hiding this comment.
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?
src/services/BookService.tsx
Outdated
export const getSubscription = async (bookId: number) => | ||
client.get(`/inventory/subscriptions/${bookId}`); |
There was a problem hiding this comment.
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
src/services/BookService.tsx
Outdated
export const getSubscription = async (bookId: number) => | ||
client.get(`/inventory/subscriptions/${bookId}`); | ||
|
||
export const postSubscribe = async (bookId: number) => |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
postSubscription
src/services/BookService.tsx
Outdated
export const postSubscribe = async (bookId: number) => | ||
client.post(`/inventory/subscriptions/subscribe/${bookId}`); | ||
|
||
export const postUnsubscribe = async (bookId: number) => |
There was a problem hiding this comment.
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
src/hooks/useSubscribe.tsx
Outdated
import { useEffect, useState } from "react"; | ||
import * as bookService from "../services/BookService"; | ||
|
||
const useSubscribe = (bookId: number) => { |
There was a problem hiding this comment.
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(() => { |
There was a problem hiding this comment.
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.
There was a problem hiding this 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
Added subscription buttons on book details page with tests.