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

[#173146890] Align bonus available type with the remote data #1869

Merged
merged 6 commits into from
Jun 4, 2020
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,
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>;