Skip to content

Commit

Permalink
release(minor): hub enhancements
Browse files Browse the repository at this point in the history
Merge PR #12
  • Loading branch information
bjardon authored Dec 1, 2024
2 parents a045855 + c6e8c0d commit 5fae6b1
Show file tree
Hide file tree
Showing 21 changed files with 730 additions and 299 deletions.
28 changes: 26 additions & 2 deletions src/app/app.routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,12 @@ import { AuthPage, SignInPage, SignUpPage } from './auth/pages';
import { HubPage } from './hub/pages';
import { UpdateProfilePage, ViewProfilePage } from './hub-profile/pages';
import { HomePage } from './hub-home/pages';
import { ViewExchangePage } from './hub-exchanges/pages';
import {
ViewExchangeGifteePage,
ViewExchangePage,
ViewExchangeSelfPage,
ViewExchangeSummaryPage,
} from './hub-exchanges/pages';

export const routes: Routes = [
{ path: '', pathMatch: 'full', redirectTo: 'hub' },
Expand All @@ -34,7 +39,26 @@ export const routes: Routes = [
{
path: 'exchanges',
children: [
{ path: ':exchangeId', component: ViewExchangePage },
{
path: ':exchangeId',
component: ViewExchangePage,
children: [
{
path: '',
pathMatch: 'full',
redirectTo: 'summary',
},
{
path: 'summary',
component: ViewExchangeSummaryPage,
},
{ path: 'self', component: ViewExchangeSelfPage },
{
path: 'giftee',
component: ViewExchangeGifteePage,
},
],
},
],
},
{
Expand Down
1 change: 1 addition & 0 deletions src/app/gift-exchanges/dtos/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export * from './create-wish-list-item.dto';
export * from './update-participant.dto';
4 changes: 4 additions & 0 deletions src/app/gift-exchanges/dtos/update-participant.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { ParticipantEntity } from '../entities';

export interface UpdateParticipantDto
extends Pick<ParticipantEntity, 'address'> {}
1 change: 1 addition & 0 deletions src/app/gift-exchanges/entities/participant.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { WishListItemEntity } from './wish-list-item.entity';

export interface ParticipantEntity {
_id: string;
address: string;
addedOn: string;
acknowledgedOn: string;
exchange: GiftExchangeEntity;
Expand Down
11 changes: 11 additions & 0 deletions src/app/gift-exchanges/services/gift-exchanges.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,17 @@ export class GiftExchangesService {
);
}

fetchOwnGiftee(exchangeId: string): Observable<ParticipantEntity> {
return this.http.get<ParticipantEntity>(
generateApiPath([
'gift-exchanges',
exchangeId,
'participants',
'giftee',
]),
);
}

acknowledgeSelf(exchangeId: string): Observable<ParticipantEntity> {
return this.http.patch<ParticipantEntity>(
generateApiPath([
Expand Down
14 changes: 12 additions & 2 deletions src/app/gift-exchanges/services/participants.service.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,26 @@
import { HttpClient } from '@angular/common/http';
import { inject, Injectable } from '@angular/core';
import { Observable } from 'rxjs';
import { WishListItemEntity } from '../entities';
import { ParticipantEntity, WishListItemEntity } from '../entities';
import { generateApiPath } from '../../../utils';
import { CreateWishListItemDto } from '../dtos';
import { CreateWishListItemDto, UpdateParticipantDto } from '../dtos';

@Injectable({
providedIn: 'root',
})
export class ParticipantsService {
private readonly http = inject(HttpClient);

patchSelf(
participantId: string,
data: UpdateParticipantDto,
): Observable<ParticipantEntity> {
return this.http.patch<ParticipantEntity>(
generateApiPath(['participants', participantId]),
data,
);
}

fetchWishListItems(
participantId: string,
): Observable<WishListItemEntity[]> {
Expand Down
39 changes: 36 additions & 3 deletions src/app/gift-exchanges/store/gift-exchanges.effects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,22 @@ export class GiftExchangesEffects {
);
});

patchSelf$ = createEffect(() => {
return this.actions$.pipe(
ofType(ParticipantsActions.patchSelf),
switchMap(({ participantId, data }) =>
this.participants.patchSelf(participantId, data).pipe(
map((participant) =>
ParticipantsActions.patchSelfSuccess({ participant }),
),
catchError((error) =>
of(ParticipantsActions.patchSelfError({ error })),
),
),
),
);
});

acknowledgeSelf$ = createEffect(() => {
return this.actions$.pipe(
ofType(ParticipantsActions.acknowledgeSelf),
Expand All @@ -75,8 +91,8 @@ export class GiftExchangesEffects {
ofType(ParticipantsActions.fetchSelf),
switchMap(({ exchangeId }) =>
this.giftExchanges.fetchSelfParticipant(exchangeId).pipe(
map((participant) =>
ParticipantsActions.fetchSelfSuccess({ participant }),
map((self) =>
ParticipantsActions.fetchSelfSuccess({ self }),
),
catchError((error) =>
of(ParticipantsActions.fetchSelfError({ error })),
Expand All @@ -86,6 +102,22 @@ export class GiftExchangesEffects {
);
});

fetchOwnGiftee$ = createEffect(() => {
return this.actions$.pipe(
ofType(ParticipantsActions.fetchOwnGiftee),
switchMap(({ exchangeId }) =>
this.giftExchanges.fetchOwnGiftee(exchangeId).pipe(
map((giftee) =>
ParticipantsActions.fetchOwnGifteeSuccess({ giftee }),
),
catchError((error) =>
of(ParticipantsActions.fetchOwnGifteeError({ error })),
),
),
),
);
});

fetchWishListItems$ = createEffect(() => {
return this.actions$.pipe(
ofType(WishListItemsActions.fetch),
Expand Down Expand Up @@ -141,6 +173,7 @@ export class GiftExchangesEffects {
of(
ParticipantsActions.fetch({ exchangeId }),
ParticipantsActions.fetchSelf({ exchangeId }),
ParticipantsActions.fetchOwnGiftee({ exchangeId }),
),
),
);
Expand All @@ -149,7 +182,7 @@ export class GiftExchangesEffects {
fetchWishListOnSelfFetch$ = createEffect(() => {
return this.actions$.pipe(
ofType(ParticipantsActions.fetchSelfSuccess),
map(({ participant }) =>
map(({ self: participant }) =>
WishListItemsActions.fetch({ participantId: participant._id }),
),
);
Expand Down
66 changes: 57 additions & 9 deletions src/app/gift-exchanges/store/gift-exchanges.reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,15 @@ export const ParticipantsReducer = createReducer(
error,
}),
),
on(
ParticipantsActions.fetchSuccess,
(state, { participants }): ParticipantsState =>
participantsAdapter.setAll(participants, {
...state,
busy: false,
error: null,
}),
),
on(
ParticipantsActions.fetchSelf,
(state): ParticipantsState => ({
Expand All @@ -83,21 +92,60 @@ export const ParticipantsReducer = createReducer(
),
on(
ParticipantsActions.fetchSelfSuccess,
(state, { participant }): ParticipantsState => ({
(state, { self }): ParticipantsState => ({
...state,
self: participant,
busy: false,
error: null,
self,
}),
),
on(
ParticipantsActions.fetchSuccess,
(state, { participants }): ParticipantsState =>
participantsAdapter.setAll(participants, {
...state,
busy: false,
error: null,
}),
ParticipantsActions.fetchOwnGiftee,
(state): ParticipantsState => ({
...state,
busy: true,
}),
),
on(
ParticipantsActions.fetchOwnGifteeError,
(state, { error }): ParticipantsState => ({
...state,
busy: false,
error,
}),
),
on(
ParticipantsActions.fetchOwnGifteeSuccess,
(state, { giftee }): ParticipantsState => ({
...state,
busy: false,
error: null,
giftee,
}),
),
on(
ParticipantsActions.patchSelf,
(state): ParticipantsState => ({
...state,
busy: true,
}),
),
on(
ParticipantsActions.patchSelfError,
(state, { error }): ParticipantsState => ({
...state,
busy: false,
error,
}),
),
on(
ParticipantsActions.patchSelfSuccess,
(state, { participant }): ParticipantsState => ({
...state,
busy: false,
error: null,
self: participant,
}),
),
on(
ParticipantsActions.acknowledgeSelf,
Expand Down
2 changes: 2 additions & 0 deletions src/app/gift-exchanges/store/gift-exchanges.state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export const giftExchangesInitialState = (): GiftExchangesState =>

export interface ParticipantsState extends EntityState<ParticipantEntity> {
self: ParticipantEntity | null;
giftee: ParticipantEntity | null;
busy: boolean;
error: unknown | null;
}
Expand All @@ -37,6 +38,7 @@ export const participantsAdapter: EntityAdapter<ParticipantEntity> =
export const participantsInitialState = (): ParticipantsState =>
participantsAdapter.getInitialState({
self: null,
giftee: null,
busy: false,
error: null,
});
Expand Down
35 changes: 34 additions & 1 deletion src/app/gift-exchanges/store/participants.actions.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { createAction, props } from '@ngrx/store';
import { ParticipantEntity } from '../entities';
import { UpdateParticipantDto } from '../dtos';

const fetch = createAction(
'[Participants] fetch',
Expand All @@ -20,13 +21,39 @@ const fetchSelf = createAction(
);
const fetchSelfSuccess = createAction(
'[Participants] fetchSelfSuccess',
props<{ participant: ParticipantEntity }>(),
props<{ self: ParticipantEntity }>(),
);
const fetchSelfError = createAction(
'[Participants] fetchSelfError',
props<{ error: unknown }>(),
);

const fetchOwnGiftee = createAction(
'[Participants] fetchOwnGiftee',
props<{ exchangeId: string }>(),
);
const fetchOwnGifteeSuccess = createAction(
'[Participants] fetchOwnGifteeSuccess',
props<{ giftee: ParticipantEntity }>(),
);
const fetchOwnGifteeError = createAction(
'[Participants] fetchSelfError',
props<{ error: unknown }>(),
);

const patchSelf = createAction(
'[Participants] patchSelf',
props<{ participantId: string; data: UpdateParticipantDto }>(),
);
const patchSelfSuccess = createAction(
'[Participants] patchSelfSuccess',
props<{ participant: ParticipantEntity }>(),
);
const patchSelfError = createAction(
'[Participants] patchSelfError',
props<{ error: unknown }>(),
);

const acknowledgeSelf = createAction(
'[Participants] acknowledgeSelf',
props<{ exchangeId: string }>(),
Expand All @@ -47,6 +74,12 @@ export const ParticipantsActions = {
fetchSelf,
fetchSelfSuccess,
fetchSelfError,
fetchOwnGiftee,
fetchOwnGifteeSuccess,
fetchOwnGifteeError,
patchSelf,
patchSelfSuccess,
patchSelfError,
acknowledgeSelf,
acknowledgeSelfSuccess,
acknowledgeSelfError,
Expand Down
2 changes: 2 additions & 0 deletions src/app/gift-exchanges/store/participants.selectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const total = createSelector(selectParticipants, selectTotal);
const busy = createSelector(selectParticipants, (state) => state.busy);
const error = createSelector(selectParticipants, (state) => state.error);
const self = createSelector(selectParticipants, (state) => state.self);
const giftee = createSelector(selectParticipants, (state) => state.giftee);

export const ParticipantsSelectors = {
ids,
Expand All @@ -24,4 +25,5 @@ export const ParticipantsSelectors = {
busy,
error,
self,
giftee,
};
3 changes: 3 additions & 0 deletions src/app/hub-exchanges/pages/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
export * from './view-exchange/view-exchange.page';
export * from './view-exchange-giftee/view-exchange-giftee.page';
export * from './view-exchange-self/view-exchange-self.page';
export * from './view-exchange-summary/view-exchange-summary.page';
Loading

0 comments on commit 5fae6b1

Please sign in to comment.