forked from pagopa/io-app
-
Notifications
You must be signed in to change notification settings - Fork 0
Feat: toy task #3
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
Open
soixdev91
wants to merge
13
commits into
master
Choose a base branch
from
feat/toy-task
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
e5648f0
microfix ios
soixdev91 5ac95d5
base Profile
soixdev91 6b05d70
fix startup saga
soixdev91 7623148
step 2
soixdev91 e7eb077
Merge branch 'master' of https://github.com/pawelPrzywara/io-app
soixdev91 379ee16
step 3
soixdev91 ef2d827
Revert "microfix ios"
soixdev91 5052347
fix: split toyProfile saga in two files
soixdev91 53a1693
fix: toyProfile navigation replaced with useIONavigation
soixdev91 9578b65
fix: toyProfileReduce's action is typed
soixdev91 86fcc67
fix: managed none state for profile fields
soixdev91 df1949a
feat: refactor variables
soixdev91 1a5252a
fix: separated success and error paths for toyProfileSaga
soixdev91 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,75 @@ | ||
| import { | ||
| Divider, | ||
| ListItemInfo, | ||
| LoadingSpinner | ||
| } from "@pagopa/io-app-design-system"; | ||
| import I18n from "i18next"; | ||
| import { IOIcons } from "@pagopa/io-app-design-system/src/components/icons/Icon.tsx"; | ||
| import * as pot from "@pagopa/ts-commons/lib/pot"; | ||
| import { useIOSelector } from "../../../store/hooks.ts"; | ||
| import { toyProfileSelector } from "../store/selectors"; | ||
| import { OperationResultScreenContent } from "../../../components/screens/OperationResultScreenContent.tsx"; | ||
| import { getNetworkErrorMessage } from "../../../utils/errors.ts"; | ||
|
|
||
| const ProfileFieldItem = ({ | ||
| label, | ||
| icon, | ||
| value | ||
| }: { | ||
| label: string; | ||
| icon: IOIcons; | ||
| value?: string; | ||
| }) => | ||
| value && ( | ||
| <> | ||
| <ListItemInfo label={label} icon={icon} value={value} /> | ||
| <Divider /> | ||
| </> | ||
| ); | ||
|
|
||
| export const ProfileFields = () => { | ||
| const toyProfilePot = useIOSelector(toyProfileSelector); | ||
|
|
||
| return pot.fold( | ||
| toyProfilePot, | ||
| () => ( | ||
| <OperationResultScreenContent | ||
| title={I18n.t("profile.toy.main.error_none")} | ||
| /> | ||
| ), | ||
| () => <LoadingSpinner />, | ||
| () => <LoadingSpinner />, | ||
| e => <OperationResultScreenContent title={getNetworkErrorMessage(e)} />, | ||
| profileData => ( | ||
| <> | ||
| <ProfileFieldItem | ||
| label={I18n.t("profile.toy.main.nameSurname")} | ||
| icon="profile" | ||
| value={`${profileData.name} ${profileData.family_name}`} | ||
| /> | ||
| <ProfileFieldItem | ||
| label={I18n.t("profile.toy.main.fiscalCode")} | ||
| icon="fiscalCodeIndividual" | ||
| value={profileData.fiscal_code} | ||
| /> | ||
| <ProfileFieldItem | ||
| label={I18n.t("profile.toy.main.email")} | ||
| icon="email" | ||
| value={profileData.email} | ||
| /> | ||
| {profileData.date_of_birth && ( | ||
| <ProfileFieldItem | ||
| label={I18n.t("profile.toy.main.birthDate")} | ||
| icon="calendar" | ||
| value={profileData.date_of_birth.toLocaleDateString(I18n.language)} | ||
| /> | ||
| )} | ||
| </> | ||
| ), | ||
| () => <LoadingSpinner />, | ||
| () => <LoadingSpinner />, | ||
| (_profileData, e) => ( | ||
| <OperationResultScreenContent title={getNetworkErrorMessage(e)} /> | ||
| ) | ||
| ); | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| import { TOY_PROFILE_ROUTES } from "./routes.ts"; | ||
|
|
||
| export type ToyProfileParamsList = { | ||
| [TOY_PROFILE_ROUTES.PROFILE_MAIN]: undefined; | ||
| [TOY_PROFILE_ROUTES.PROFILE_WARN]: undefined; | ||
| [TOY_PROFILE_ROUTES.PROFILE_CONFIRM_DELETE]: undefined; | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| export const TOY_PROFILE_ROUTES = { | ||
| PROFILE_MAIN: "PROFILE_MAIN", | ||
| PROFILE_WARN: "PROFILE_WARN", | ||
| PROFILE_CONFIRM_DELETE: "PROFILE_CONFIRM_DELETE" | ||
| } as const; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| import { createStackNavigator } from "@react-navigation/stack"; | ||
| import { ProfileHomeScreen } from "../screens/ProfileHomeScreen.tsx"; | ||
| import { isGestureEnabled } from "../../../utils/navigation.ts"; | ||
| import { ProfileWarnScreen } from "../screens/ProfileWarnScreen.tsx"; | ||
| import { ProfileConfirmDeleteScreen } from "../screens/ProfileConfirmDeleteScreen.tsx"; | ||
| import { TOY_PROFILE_ROUTES } from "./routes"; | ||
| import { ToyProfileParamsList } from "./params.ts"; | ||
|
|
||
| const Stack = createStackNavigator<ToyProfileParamsList>(); | ||
|
|
||
| /** | ||
| * A navigator for all the screens of the Settings section | ||
| */ | ||
| const ToyProfileNavigator = () => ( | ||
| <Stack.Navigator | ||
| initialRouteName={TOY_PROFILE_ROUTES.PROFILE_MAIN} | ||
| screenOptions={{ gestureEnabled: isGestureEnabled, headerMode: "screen" }} | ||
| > | ||
| <Stack.Screen | ||
| name={TOY_PROFILE_ROUTES.PROFILE_MAIN} | ||
| component={ProfileHomeScreen} | ||
| /> | ||
| <Stack.Screen | ||
| name={TOY_PROFILE_ROUTES.PROFILE_WARN} | ||
| component={ProfileWarnScreen} | ||
| /> | ||
| <Stack.Screen | ||
| name={TOY_PROFILE_ROUTES.PROFILE_CONFIRM_DELETE} | ||
| component={ProfileConfirmDeleteScreen} | ||
| /> | ||
| </Stack.Navigator> | ||
| ); | ||
|
|
||
| export default ToyProfileNavigator; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| import * as E from "fp-ts/lib/Either"; | ||
| import * as O from "fp-ts/lib/Option"; | ||
| import { call, put } from "typed-redux-saga/macro"; | ||
| import { BackendClient } from "../../../api/backend.ts"; | ||
| import { ReduxSagaEffect, SagaCallReturnType } from "../../../types/utils.ts"; | ||
| import { withRefreshApiCall } from "../../authentication/fastLogin/saga/utils"; | ||
| import { getToyProfileDetailsAction } from "../store/actions"; | ||
| import { getNetworkError } from "../../../utils/errors.ts"; | ||
| import { ToyProfileResponse } from "../types"; | ||
|
|
||
| export function* handleLoadToyProfileSaga( | ||
| getProfile: ReturnType<typeof BackendClient>["getProfile"] | ||
| ): Generator< | ||
| ReduxSagaEffect, | ||
| O.Option<ToyProfileResponse>, | ||
| SagaCallReturnType<typeof getProfile> | ||
| > { | ||
| try { | ||
| const resp = (yield* call( | ||
| withRefreshApiCall, | ||
| getProfile({}) | ||
| )) as unknown as SagaCallReturnType<typeof getProfile>; | ||
|
|
||
| if (E.isRight(resp)) { | ||
| const { status, value } = resp.right; | ||
|
|
||
| if (status === 200) { | ||
| const payload = value as ToyProfileResponse; | ||
| yield* put(getToyProfileDetailsAction.success(payload)); | ||
| return O.some(payload); | ||
| } | ||
|
|
||
| throw new Error(`response status ${status}`); | ||
| } | ||
|
|
||
| const messages = resp.left.map(e => e.message).join(", "); | ||
|
|
||
| throw new Error(`error: ${messages}`); | ||
| } catch (err) { | ||
| // FAILED ACTION | ||
| yield* put(getToyProfileDetailsAction.failure(getNetworkError(err))); | ||
| } | ||
| return O.none; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| import { takeLatest } from "typed-redux-saga/macro"; | ||
| import { getType } from "typesafe-actions"; | ||
| import { BackendClient } from "../../../api/backend.ts"; | ||
| import { ReduxSagaEffect } from "../../../types/utils.ts"; | ||
| import { getToyProfileDetailsAction } from "../store/actions"; | ||
| import { handleLoadToyProfileSaga } from "./handleLoadToyProfileSaga.ts"; | ||
|
|
||
| export function* watchToyProfileSaga( | ||
| getProfile: ReturnType<typeof BackendClient>["getProfile"] | ||
| ): Iterator<ReduxSagaEffect> { | ||
| yield* takeLatest( | ||
| getType(getToyProfileDetailsAction.request), | ||
| handleLoadToyProfileSaga, | ||
| getProfile | ||
| ); | ||
| } |
97 changes: 97 additions & 0 deletions
97
ts/features/toyProfile/screens/ProfileConfirmDeleteScreen.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,97 @@ | ||
| import { ComponentProps } from "react"; | ||
| import I18n from "i18next"; | ||
| import { useDispatch } from "react-redux"; | ||
| import * as pot from "@pagopa/ts-commons/lib/pot"; | ||
| import { ListItemInfo, LoadingSpinner } from "@pagopa/io-app-design-system"; | ||
| import { IOScrollView } from "../../../components/ui/IOScrollView.tsx"; | ||
| import { useIONavigation } from "../../../navigation/params/AppParamsList.ts"; | ||
| import { IOScrollViewWithLargeHeader } from "../../../components/ui/IOScrollViewWithLargeHeader.tsx"; | ||
| import { ProfileFields } from "../components/ProfileFields.tsx"; | ||
| import { useIOSelector } from "../../../store/hooks.ts"; | ||
| import { userDataProcessingSelector } from "../../settings/common/store/selectors/userDataProcessing.ts"; | ||
| import { UserDataProcessingChoiceEnum } from "../../../../definitions/backend/UserDataProcessingChoice.ts"; | ||
| import { upsertUserDataProcessing } from "../../settings/common/store/actions/userDataProcessing.ts"; | ||
|
|
||
| export const ProfileConfirmDeleteScreen = () => { | ||
| const navigation = useIONavigation(); | ||
|
|
||
| const dispatch = useDispatch(); | ||
|
|
||
| const deletePot = useIOSelector( | ||
| s => userDataProcessingSelector(s)[UserDataProcessingChoiceEnum.DELETE] | ||
| ); | ||
|
|
||
| const delHasValue = pot.isSome(deletePot) && deletePot.value?.status; | ||
|
|
||
| const renderActionProps = (): ComponentProps< | ||
| typeof IOScrollView | ||
| >["actions"] => { | ||
| const onDeletePress = () => { | ||
| dispatch( | ||
| upsertUserDataProcessing.request(UserDataProcessingChoiceEnum.DELETE) | ||
| ); | ||
| }; | ||
|
|
||
| if (pot.isError(deletePot)) { | ||
| return { | ||
| type: "TwoButtons", | ||
| primary: { | ||
| label: I18n.t("profile.toy.confirm_delete.buttons.cancel"), | ||
| onPress: navigation.popToTop | ||
| }, | ||
| secondary: { | ||
| label: I18n.t("profile.toy.confirm_delete.buttons.retry"), | ||
| onPress: onDeletePress | ||
| } | ||
| }; | ||
| } | ||
|
|
||
| if (delHasValue) { | ||
| return { | ||
| type: "SingleButton", | ||
| primary: { | ||
| label: I18n.t("profile.toy.confirm_delete.buttons.close"), | ||
| onPress: navigation.popToTop | ||
| } | ||
| }; | ||
| } | ||
|
|
||
| return { | ||
| type: "TwoButtons", | ||
| primary: { | ||
| label: I18n.t("profile.toy.confirm_delete.buttons.cancel"), | ||
| onPress: navigation.popToTop | ||
| }, | ||
| secondary: { | ||
| label: I18n.t("profile.toy.confirm_delete.buttons.continue"), | ||
| onPress: onDeletePress | ||
| } | ||
| }; | ||
| }; | ||
|
|
||
| return ( | ||
| <IOScrollViewWithLargeHeader | ||
| includeContentMargins | ||
| title={{ | ||
| label: I18n.t( | ||
| delHasValue | ||
| ? "profile.toy.confirm_delete.header_deleted" | ||
| : "profile.toy.confirm_delete.header" | ||
| ) | ||
| }} | ||
| headerActionsProp={{ | ||
| showHelp: true | ||
| }} | ||
| actions={renderActionProps()} | ||
| > | ||
| {pot.isError(deletePot) && ( | ||
| <ListItemInfo value={deletePot.error.message} /> | ||
| )} | ||
| {pot.isLoading(deletePot) && <LoadingSpinner />} | ||
| {!delHasValue && <ProfileFields />} | ||
| {delHasValue && ( | ||
| <ListItemInfo value={I18n.t("profile.toy.confirm_delete.deleted")} /> | ||
| )} | ||
| </IOScrollViewWithLargeHeader> | ||
| ); | ||
| }; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
In this case since the file contains both the handlers and the watcher, consider renaming the file to
index.tsThere 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.
I think, just to follow our conventions, it will be better to separate this into two different files:
watchToyProfileSagaloadToyProfileSagaand I think it will be better renamed ithandleLoadToyProfileSagaThere 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.
solved with 5052347
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.
solved with 5052347