Skip to content

Commit

Permalink
fix: display if subscription cancelled
Browse files Browse the repository at this point in the history
  • Loading branch information
AykutSarac committed Jul 18, 2023
1 parent 7e8fdca commit 03aef80
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 7 deletions.
9 changes: 6 additions & 3 deletions src/containers/Modals/AccountModal/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,10 @@ const StyledContainer = styled.div`
`;

export const AccountModal: React.FC<ModalProps> = ({ opened, onClose }) => {
const setVisible = useModal(state => state.setVisible);
const user = useUser(state => state.user);
const isPremium = useUser(state => state.premium);
const premiumCancelled = useUser(state => state.premiumCancelled);
const setVisible = useModal(state => state.setVisible);
const logout = useUser(state => state.logout);

return (
Expand All @@ -67,7 +68,9 @@ export const AccountModal: React.FC<ModalProps> = ({ opened, onClose }) => {
ACCOUNT STATUS
<div>
{isPremium ? (
<Badge color="orange">Premium</Badge>
<Badge color={premiumCancelled ? "teal" : "indigo"}>
Premium {premiumCancelled && "(Cancelled)"}
</Badge>
) : (
<Badge variant="outline" color="gray">
Free
Expand All @@ -92,7 +95,7 @@ export const AccountModal: React.FC<ModalProps> = ({ opened, onClose }) => {
</Group>
<Divider py="xs" />
<Group position="right">
{isPremium ? (
{isPremium && !premiumCancelled ? (
<Button
variant="light"
color="red"
Expand Down
1 change: 1 addition & 0 deletions src/containers/Modals/CancelPremiumModal/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export const CancelPremiumModal: React.FC<ModalProps> = ({ opened, onClose }) =>
}

toast.success("Cancelled premium plan!");
setTimeout(() => window.location.reload(), 2500);
} catch (err) {
console.error(err);
} finally {
Expand Down
15 changes: 11 additions & 4 deletions src/store/useUser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,14 @@ interface UserStates {
user: User | null;
isAuthenticated: boolean;
premium: boolean;
premiumCancelled: boolean;
}

const initialStates: UserStates = {
user: null,
isAuthenticated: false,
premium: false,
premiumCancelled: false,
};

const useUser = create<UserStates & UserActions>()(set => ({
Expand All @@ -57,9 +59,9 @@ const useUser = create<UserStates & UserActions>()(set => ({
},
login: user => set({ user: user as unknown as User, isAuthenticated: true }),
checkSession: async () => {
if (isDevelopment) {
return set({ user: devUser as User, isAuthenticated: true, premium: true });
}
// if (isDevelopment) {
// return set({ user: devUser as User, isAuthenticated: true, premium: true });
// }

const currentSession = altogic.auth.getSession();

Expand All @@ -76,7 +78,12 @@ const useUser = create<UserStates & UserActions>()(set => ({
const { data: premiumData } = await altogic.endpoint.get("/isPremium");

setUser({ id: user._id, email: user.email, username: user.name });
set({ user: user as User, isAuthenticated: true, premium: premiumData.premium });
set({
user: user as User,
isAuthenticated: true,
premium: premiumData.premium,
premiumCancelled: premiumData?.status === "cancelled" || false,
});
} else if (new URLSearchParams(window.location.search).get("access_token")) {
const { errors, user } = await altogic.auth.getAuthGrant();

Expand Down

0 comments on commit 03aef80

Please sign in to comment.