Skip to content

Commit

Permalink
feat: [#173146890] Align bonus available type with the remote data (#…
Browse files Browse the repository at this point in the history
…1869)

* [#173146890] align bonus available type with the remote data
refactoring

* [#173146890] fix refactoring errors

* [#173146890] fix refactoring errors

* [#173146890] fix refactoring errors

* [#173146890] change filed from active -> is_active

* [#173146890] update comment
  • Loading branch information
Undermaken authored Jun 4, 2020
1 parent 77f8efa commit 6d8f969
Show file tree
Hide file tree
Showing 10 changed files with 70 additions and 54 deletions.
9 changes: 6 additions & 3 deletions ts/features/bonusVacanze/api/backendBonusVacanze.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ import {
} from "italia-ts-commons/lib/requests";
import { ProblemJson } from "../../../../definitions/backend/ProblemJson";
import { defaultRetryingFetch } from "../../../utils/fetch";
import { BonusList, BonusListT } from "../types/bonusList";
import {
BonusesAvailable,
BonusesAvailableCodec
} from "../types/bonusesAvailable";
import { BonusVacanze, BonusVacanzeT } from "../types/bonusVacanzeActivation";
import {
EligibilityCheck,
Expand All @@ -25,7 +28,7 @@ type GetBonusListT = IGetApiRequestType<
{},
never,
never,
BasicResponseType<BonusList>
BasicResponseType<BonusesAvailable>
>;

type EligibilityCheckT = IGetApiRequestType<
Expand Down Expand Up @@ -140,7 +143,7 @@ const getAvailableBonusesT: GetBonusListT = {
url: () => `/bonus/vacanze`,
query: _ => ({}),
headers: () => ({}),
response_decoder: basicResponseDecoder(BonusListT)
response_decoder: basicResponseDecoder(BonusesAvailableCodec)
};

//
Expand Down
4 changes: 2 additions & 2 deletions ts/features/bonusVacanze/components/AvailableBonusItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ import IconFont from "../../../components/ui/IconFont";
import { makeFontStyleObject } from "../../../theme/fonts";
import customVariables from "../../../theme/variables";
import { formatDateAsLocal } from "../../../utils/dates";
import { BonusItem } from "../types/bonusList";
import { BonusAvailable } from "../types/bonusesAvailable";

type Props = {
bonusItem: BonusItem;
bonusItem: BonusAvailable;
onPress: () => void;
};

Expand Down
4 changes: 2 additions & 2 deletions ts/features/bonusVacanze/components/RequestBonus.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import H5 from "../../../components/ui/H5";
import I18n from "../../../i18n";
import customVariables from "../../../theme/variables";
import { maybeInnerProperty } from "../../../utils/options";
import { BonusList } from "../types/bonusList";
import { BonusesAvailable } from "../types/bonusesAvailable";
import { BonusVacanze } from "../types/bonusVacanzeActivation";
import { ID_BONUS_VACANZE_TYPE } from "../utils/bonus";
import ActiveBonus from "./ActiveBonus";
Expand All @@ -16,7 +16,7 @@ type OwnProps = {
onButtonPress: () => void;
onBonusPress: (bonus: BonusVacanze, validFrom?: Date, validTo?: Date) => void;
bonus: pot.Pot<BonusVacanze, Error>;
availableBonusesList: BonusList;
availableBonusesList: BonusesAvailable;
};

const styles = StyleSheet.create({
Expand Down
6 changes: 3 additions & 3 deletions ts/features/bonusVacanze/screens/AvailableBonusScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import AvailableBonusItem from "../components/AvailableBonusItem";
import { availableBonusesLoad } from "../store/actions/bonusVacanze";
import { availableBonusesSelector } from "../store/reducers/availableBonuses";
import { bonusVacanzeActivationSelector } from "../store/reducers/bonusVacanzeActivation";
import { BonusItem } from "../types/bonusList";
import { BonusAvailable } from "../types/bonusesAvailable";
import { BonusVacanze } from "../types/bonusVacanzeActivation";
import { ID_BONUS_VACANZE_TYPE, isBonusActive } from "../utils/bonus";

Expand All @@ -47,7 +47,7 @@ const styles = StyleSheet.create({
* instead if bonus is not active the user can navigate to the begin of request flow.
*/
class AvailableBonusScreen extends React.PureComponent<Props> {
private renderListItem = (info: ListRenderItemInfo<BonusItem>) => {
private renderListItem = (info: ListRenderItemInfo<BonusAvailable>) => {
const { activeBonus } = this.props;
const item = info.item;
const bonusVacanzeCategory = this.props.availableBonusesList.items.find(
Expand Down Expand Up @@ -135,7 +135,7 @@ const mapDispatchToProps = (dispatch: Dispatch) => ({
navigateBack: () => dispatch(navigateBack()),
loadAvailableBonuses: () => dispatch(availableBonusesLoad.request()),
// TODO Add the param to navigate to proper bonus by name (?)
navigateToBonusRequest: (bonusItem: BonusItem) =>
navigateToBonusRequest: (bonusItem: BonusAvailable) =>
dispatch(navigateToBonusRequestInformation({ bonusItem })),
// TODO Add the param to bonus detail if a bonus is already active
navigateToBonusDetail: (
Expand Down
4 changes: 2 additions & 2 deletions ts/features/bonusVacanze/screens/BonusInformationScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ import { navigateBack } from "../../../store/actions/navigation";
import { ReduxProps } from "../../../store/actions/types";
import themeVariables from "../../../theme/variables";
import { FooterTwoButtons } from "../components/markdown/FooterTwoButtons";
import { BonusItem } from "../types/bonusList";
import { BonusAvailable } from "../types/bonusesAvailable";

type NavigationParams = Readonly<{
bonusItem: BonusItem;
bonusItem: BonusAvailable;
}>;

type Props = ReduxProps &
Expand Down
4 changes: 2 additions & 2 deletions ts/features/bonusVacanze/store/actions/bonusVacanze.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {
createAsyncAction,
createStandardAction
} from "typesafe-actions";
import { BonusList } from "../../types/bonusList";
import { BonusesAvailable } from "../../types/bonusesAvailable";
import { BonusVacanze } from "../../types/bonusVacanzeActivation";
import { EligibilityCheck, EligibilityId } from "../../types/eligibility";
import { EligibilityRequestProgressEnum } from "../reducers/eligibility";
Expand All @@ -16,7 +16,7 @@ export const availableBonusesLoad = createAsyncAction(
"BONUS_AVAILABLE_REQUEST",
"BONUS_AVAILABLE_SUCCESS",
"BONUS_AVAILABLE_FAILURE"
)<void, BonusList, Error>();
)<void, BonusesAvailable, Error>();

export const checkBonusEligibility = createAsyncAction(
"BONUS_CHECK_ELIGIBILITY_REQUEST",
Expand Down
6 changes: 3 additions & 3 deletions ts/features/bonusVacanze/store/reducers/availableBonuses.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ import * as pot from "italia-ts-commons/lib/pot";
import { getType } from "typesafe-actions";
import { Action } from "../../../../store/actions/types";
import { GlobalState } from "../../../../store/reducers/types";
import { BonusList } from "../../types/bonusList";
import { BonusesAvailable } from "../../types/bonusesAvailable";
import { availableBonusesLoad } from "../actions/bonusVacanze";

export type AvailableBonusesState = pot.Pot<BonusList, Error>;
export type AvailableBonusesState = pot.Pot<BonusesAvailable, Error>;

const INITIAL_STATE: AvailableBonusesState = pot.none;

Expand All @@ -28,6 +28,6 @@ const reducer = (
// Selectors
export const availableBonusesSelector = (
state: GlobalState
): pot.Pot<BonusList, Error> => state.bonus.availableBonuses;
): pot.Pot<BonusesAvailable, Error> => state.bonus.availableBonuses;

export default reducer;
29 changes: 0 additions & 29 deletions ts/features/bonusVacanze/types/bonusList.ts

This file was deleted.

34 changes: 34 additions & 0 deletions ts/features/bonusVacanze/types/bonusesAvailable.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/**
* TEMPORARY TYPE DEFINITION
* this type must be replaced with the one auto-generated from spec
*/
import * as t from "io-ts";
import { NonNegativeInteger } from "italia-ts-commons/lib/numbers";
import { Timestamp } from "../../../../definitions/backend/Timestamp";

const BonusAvailableR = t.interface({
id_type: NonNegativeInteger,
name: t.string,
is_active: t.boolean,
description: t.string,
valid_from: Timestamp,
valid_to: Timestamp
});
const BonusAvailableO = t.partial({
cover: t.string,
service_id: t.string
});
export const BonusAvailableCodec = t.intersection(
[BonusAvailableR, BonusAvailableO],
"BonusAvailable"
);
const BonusListR = t.interface({
items: t.readonlyArray(BonusAvailableCodec, "array of available bonuses")
});
const BonusListRO = t.partial({});
export const BonusesAvailableCodec = t.intersection(
[BonusListR, BonusListRO],
"BonusesAvailable"
);
export type BonusesAvailable = t.TypeOf<typeof BonusesAvailableCodec>;
export type BonusAvailable = t.TypeOf<typeof BonusAvailableCodec>;
24 changes: 16 additions & 8 deletions ts/screens/wallet/WalletHomeScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,13 @@ class WalletHomeScreen extends React.PureComponent<Props> {
return true;
};

private loadBonusVacanze = () => {
if (bonusVacanzeEnabled) {
this.props.loadAvailableBonuses();
this.props.loadBonusVacanzeFromId("FAKE_ID");
}
};

public componentDidMount() {
// WIP loadTransactions should not be called from here
// (transactions should be persisted & fetched periodically)
Expand All @@ -196,10 +203,7 @@ class WalletHomeScreen extends React.PureComponent<Props> {
customVariables.brandDarkGray
);
}); // tslint:disable-line no-object-mutation
if (bonusVacanzeEnabled) {
this.props.loadAvailableBonuses();
this.props.loadBonusVacanzeFromId("FAKE_ID");
}
this.loadBonusVacanze();
BackHandler.addEventListener("hardwareBackPress", this.handleBackPress);
}

Expand Down Expand Up @@ -456,6 +460,13 @@ class WalletHomeScreen extends React.PureComponent<Props> {
);
}

// triggered on pull to refresh
private handleOnRefresh = () => {
this.loadBonusVacanze();
this.props.loadTransactions(this.props.transactionsLoadedLength);
this.props.loadWallets();
};

public render(): React.ReactNode {
const { potWallets, potTransactions, historyPayments } = this.props;

Expand Down Expand Up @@ -485,10 +496,7 @@ class WalletHomeScreen extends React.PureComponent<Props> {

const walletRefreshControl = (
<RefreshControl
onRefresh={() => {
this.props.loadTransactions(this.props.transactionsLoadedLength);
this.props.loadWallets();
}}
onRefresh={this.handleOnRefresh}
refreshing={false}
tintColor={"transparent"} // iOS
/>
Expand Down

0 comments on commit 6d8f969

Please sign in to comment.