-
Notifications
You must be signed in to change notification settings - Fork 4
cp-159: Add more steps to the survey#159 #319
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
Draft
BrianSammit
wants to merge
21
commits into
development
Choose a base branch
from
task/cp-159-add-more-steps-survey
base: development
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.
Draft
Changes from 10 commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
46dd53c
cp-159: + survey navigation parameter and survey screen enum
BrianSammit 3a88d5b
cp-159: + add pages with more steps to the survey
BrianSammit d9b25bc
cp-159: + fix bug of white background color in nested stack and fix p…
BrianSammit 1f313f8
cp-159: + get the journaling step data and send it to the back-end
BrianSammit c9f40e5
cp-159: + get the feeling steps data and send it to the back-end
BrianSammit 4fe01dd
cp-159: + get the goals steps data and send it to the back-end
BrianSammit 1b29104
cp-159: + get the worries steps data and send it to the back-end
BrianSammit 9224ce5
cp-159: + get the worries steps data and send it to the back-end
BrianSammit 1c4e8d7
cp-159: + get the meditation steps data and send it to the back-end
BrianSammit 3ac21bd
Merge branch 'development' into task/cp-159-add-more-steps-survey
iamAlinaaa 6538027
cp-159: + add a component for reuse in screens and move the stack sur…
BrianSammit 011cec8
cp-159: + redux slice to manage the state of the survey
BrianSammit 8bc5bb9
cp-159: + the data receive from each step and update the slice
BrianSammit a7fb50c
cp-159: + collect the data from steps and send it
BrianSammit f94cc12
Merge branch 'task/cp-159-add-more-steps-survey' of https://github.co…
BrianSammit f686892
Merge branch 'development' of https://github.com/BinaryStudioAcademy/…
BrianSammit 2c3c0b3
cp-159: + all steps to survey and fix styles
BrianSammit a502750
cp-159: * fix misspelling that generate bug sending data to back end
BrianSammit b872bfc
cp-159: + form for one option and and validation
BrianSammit 3758042
cp-159: * merge conflicts
BrianSammit 3e9d897
Merge branch 'development' into task/cp-159-add-more-steps-survey
BrianSammit 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
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
10 changes: 10 additions & 0 deletions
10
mobile/src/libs/enums/navigation/survey-screen-name.enum.ts
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,10 @@ | ||
| const SurveyScreenName = { | ||
| PREFERENCES: 'preferences', | ||
| FEELINGS: 'feeling', | ||
| GOALS: 'goals', | ||
| WORRIES: 'worries', | ||
| MEDITATION_EXPERIENCE: 'meditation experience', | ||
| JOURNALING_EXPERIENCE: 'journaling experience', | ||
| } as const; | ||
|
|
||
| export { SurveyScreenName }; |
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
12 changes: 12 additions & 0 deletions
12
mobile/src/libs/types/navigation/survey-navigation-parameter-list.type.ts
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,12 @@ | ||
| import { type SurveyScreenName } from '#libs/enums/enums'; | ||
|
|
||
| type SurveyNavigationParameterList = { | ||
| [SurveyScreenName.PREFERENCES]: undefined | object; | ||
| [SurveyScreenName.FEELINGS]: undefined | object; | ||
| [SurveyScreenName.GOALS]: undefined | object; | ||
| [SurveyScreenName.WORRIES]: undefined | object; | ||
| [SurveyScreenName.MEDITATION_EXPERIENCE]: undefined | object; | ||
| [SurveyScreenName.JOURNALING_EXPERIENCE]: undefined | object; | ||
|
Comment on lines
+4
to
+9
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Provide more specific types |
||
| }; | ||
|
|
||
| export { type SurveyNavigationParameterList }; | ||
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
124 changes: 124 additions & 0 deletions
124
mobile/src/screens/survey/components/feelings-step/feelings-step.tsx
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Create a generic component for reusing, it is not a good practise of your approach |
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,124 @@ | ||
| import { type RouteProp } from '@react-navigation/native'; | ||
| import { type NativeStackNavigationProp } from '@react-navigation/native-stack'; | ||
| import React from 'react'; | ||
|
|
||
| import { Button, Input, ScrollView, Text } from '#libs/components/components'; | ||
| import { SurveyScreenName } from '#libs/enums/enums'; | ||
| import { | ||
| useAppForm, | ||
| useCallback, | ||
| useFormController, | ||
| useNavigation, | ||
| } from '#libs/hooks/hooks'; | ||
| import { type SurveyNavigationParameterList } from '#libs/types/types'; | ||
| import { | ||
| getSurveyCategories, | ||
| type SurveyInputDto, | ||
| surveyInputValidationSchema, | ||
| } from '#packages/survey/survey'; | ||
| import { | ||
| DEFAULT_SURVEY_PAYLOAD, | ||
| FEELING_CATEGORIES, | ||
| TEXTAREA_ROWS_COUNT, | ||
| } from '#screens/survey/libs/constants'; | ||
|
|
||
| import { SurveyCategory } from '../components'; | ||
| import { styles } from './styles'; | ||
|
|
||
| type FeelingsStepProperties = { | ||
| route: RouteProp< | ||
| SurveyNavigationParameterList, | ||
| typeof SurveyScreenName.FEELINGS | ||
| >; | ||
| }; | ||
|
|
||
| type FeelingsStepInitialParameters = { | ||
| setFeelingsSurvey: (payload: string[]) => void; | ||
| }; | ||
|
|
||
| const FeelingsStep: React.FC<FeelingsStepProperties> = ({ route }) => { | ||
| const { setFeelingsSurvey } = route.params as FeelingsStepInitialParameters; | ||
| const navigation = | ||
| useNavigation<NativeStackNavigationProp<SurveyNavigationParameterList>>(); | ||
|
|
||
| const { control, errors, isValid, handleSubmit } = useAppForm<SurveyInputDto>( | ||
| { | ||
| defaultValues: DEFAULT_SURVEY_PAYLOAD, | ||
| validationSchema: surveyInputValidationSchema, | ||
| }, | ||
| ); | ||
| const { | ||
| field: { onChange: onCategoryChange, value: categoriesValue }, | ||
| } = useFormController({ | ||
| name: 'preferences', | ||
| control, | ||
| }); | ||
| const hasOther = categoriesValue.includes('Other'); | ||
| const handleFieldChange = useCallback( | ||
| (option: string) => { | ||
| if (categoriesValue.includes(option)) { | ||
| onCategoryChange( | ||
| categoriesValue.filter((category) => { | ||
| return category !== option; | ||
| }), | ||
| ); | ||
|
|
||
| return; | ||
| } | ||
|
|
||
| onCategoryChange([...categoriesValue, option]); | ||
| }, | ||
| [categoriesValue, onCategoryChange], | ||
| ); | ||
|
|
||
| const handleSurveySubmit = useCallback( | ||
| (payload: SurveyInputDto) => { | ||
| setFeelingsSurvey(getSurveyCategories(payload)); | ||
| }, | ||
| [setFeelingsSurvey], | ||
| ); | ||
|
|
||
| const handleContinue = (): void => { | ||
| navigation.navigate(SurveyScreenName.GOALS); | ||
| void handleSubmit(handleSurveySubmit)(); | ||
| }; | ||
|
|
||
| const handleBack = (): void => { | ||
| navigation.navigate(SurveyScreenName.PREFERENCES); | ||
| }; | ||
|
|
||
| return ( | ||
| <ScrollView | ||
| style={styles.surveyContainer} | ||
| showsVerticalScrollIndicator={false} | ||
| > | ||
| <Text style={styles.titleText}>How have you been feeling lately?</Text> | ||
| {FEELING_CATEGORIES.map((category) => { | ||
| return ( | ||
| <SurveyCategory | ||
| key={category} | ||
| onChange={handleFieldChange} | ||
| label={category} | ||
| /> | ||
| ); | ||
| })} | ||
| {hasOther && ( | ||
| <Input | ||
| control={control} | ||
| errors={errors} | ||
| name="other" | ||
| placeholder="Enter your preferences" | ||
| rowsCount={TEXTAREA_ROWS_COUNT} | ||
| /> | ||
| )} | ||
| <Button | ||
| label="Continue" | ||
| onPress={handleContinue} | ||
| isDisabled={!isValid} | ||
| type="outlined" | ||
| /> | ||
| <Button label="Go back" onPress={handleBack} type="solid" /> | ||
| </ScrollView> | ||
| ); | ||
| }; | ||
| export { FeelingsStep }; |
32 changes: 32 additions & 0 deletions
32
mobile/src/screens/survey/components/feelings-step/styles.ts
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,32 @@ | ||
| import { StyleSheet } from 'react-native'; | ||
|
|
||
| import { AppColor } from '#libs/enums/enums'; | ||
|
|
||
| const styles = StyleSheet.create({ | ||
| surveyContainer: { | ||
| flex: 1, | ||
| marginTop: 40, | ||
| paddingHorizontal: 55, | ||
| }, | ||
| otherTextInput: { | ||
| backgroundColor: AppColor.BLUE_100_ALPHA_70, | ||
| borderRadius: 8, | ||
| padding: 8, | ||
| borderWidth: 1, | ||
| marginBottom: 20, | ||
| borderColor: AppColor.WHITE, | ||
| color: AppColor.BLUE_300, | ||
| fontSize: 16, | ||
| }, | ||
| titleText: { | ||
| fontSize: 22, | ||
| color: AppColor.WHITE, | ||
| marginBottom: 30, | ||
| marginTop: 30, | ||
| }, | ||
| placeholder: { | ||
| color: AppColor.WHITE, | ||
| }, | ||
| }); | ||
|
|
||
| export { styles }; |
126 changes: 126 additions & 0 deletions
126
mobile/src/screens/survey/components/goals-step/goals-step.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,126 @@ | ||
| import { type RouteProp } from '@react-navigation/native'; | ||
| import { type NativeStackNavigationProp } from '@react-navigation/native-stack'; | ||
| import React from 'react'; | ||
|
|
||
| import { Button, Input, ScrollView, Text } from '#libs/components/components'; | ||
| import { SurveyScreenName } from '#libs/enums/enums'; | ||
| import { | ||
| useAppForm, | ||
| useCallback, | ||
| useFormController, | ||
| useNavigation, | ||
| } from '#libs/hooks/hooks'; | ||
| import { type SurveyNavigationParameterList } from '#libs/types/types'; | ||
| import { | ||
| getSurveyCategories, | ||
| type SurveyInputDto, | ||
| surveyInputValidationSchema, | ||
| } from '#packages/survey/survey'; | ||
| import { | ||
| DEFAULT_SURVEY_PAYLOAD, | ||
| GOALS_CATEGORIES, | ||
| TEXTAREA_ROWS_COUNT, | ||
| } from '#screens/survey/libs/constants'; | ||
|
|
||
| import { SurveyCategory } from '../components'; | ||
| import { styles } from './styles'; | ||
|
|
||
| type GoalsStepProperties = { | ||
| route: RouteProp< | ||
| SurveyNavigationParameterList, | ||
| typeof SurveyScreenName.GOALS | ||
| >; | ||
| }; | ||
|
|
||
| type GoalsStepInitialParameters = { | ||
| setGoalsSurvey: (payload: string[]) => void; | ||
| }; | ||
|
|
||
| const GoalsStep: React.FC<GoalsStepProperties> = ({ route }) => { | ||
| const { setGoalsSurvey } = route.params as GoalsStepInitialParameters; | ||
| const navigation = | ||
| useNavigation<NativeStackNavigationProp<SurveyNavigationParameterList>>(); | ||
|
|
||
| const { control, errors, isValid, handleSubmit } = useAppForm<SurveyInputDto>( | ||
| { | ||
| defaultValues: DEFAULT_SURVEY_PAYLOAD, | ||
| validationSchema: surveyInputValidationSchema, | ||
| }, | ||
| ); | ||
| const { | ||
| field: { onChange: onCategoryChange, value: categoriesValue }, | ||
| } = useFormController({ | ||
| name: 'preferences', | ||
| control, | ||
| }); | ||
| const hasOther = categoriesValue.includes('Other'); | ||
| const handleFieldChange = useCallback( | ||
| (option: string) => { | ||
| if (categoriesValue.includes(option)) { | ||
| onCategoryChange( | ||
| categoriesValue.filter((category) => { | ||
| return category !== option; | ||
| }), | ||
| ); | ||
|
|
||
| return; | ||
| } | ||
|
|
||
| onCategoryChange([...categoriesValue, option]); | ||
| }, | ||
| [categoriesValue, onCategoryChange], | ||
| ); | ||
|
|
||
| const handleSurveySubmit = useCallback( | ||
| (payload: SurveyInputDto) => { | ||
| setGoalsSurvey(getSurveyCategories(payload)); | ||
| }, | ||
| [setGoalsSurvey], | ||
| ); | ||
|
|
||
| const handleContinue = (): void => { | ||
| navigation.navigate(SurveyScreenName.WORRIES); | ||
| void handleSubmit(handleSurveySubmit)(); | ||
| }; | ||
|
|
||
| const handleBack = (): void => { | ||
| navigation.navigate(SurveyScreenName.FEELINGS); | ||
| }; | ||
|
|
||
| return ( | ||
| <ScrollView | ||
| style={styles.surveyContainer} | ||
| showsVerticalScrollIndicator={false} | ||
| > | ||
| <Text style={styles.titleText}> | ||
| What do you want to achive with CalmPal? | ||
| </Text> | ||
| {GOALS_CATEGORIES.map((category) => { | ||
| return ( | ||
| <SurveyCategory | ||
| key={category} | ||
| onChange={handleFieldChange} | ||
| label={category} | ||
| /> | ||
| ); | ||
| })} | ||
| {hasOther && ( | ||
| <Input | ||
| control={control} | ||
| errors={errors} | ||
| name="other" | ||
| placeholder="Enter your preferences" | ||
| rowsCount={TEXTAREA_ROWS_COUNT} | ||
| /> | ||
| )} | ||
| <Button | ||
| label="Continue" | ||
| onPress={handleContinue} | ||
| isDisabled={!isValid} | ||
| type="outlined" | ||
| /> | ||
| <Button label="Go back" onPress={handleBack} type="solid" /> | ||
| </ScrollView> | ||
| ); | ||
| }; | ||
| export { GoalsStep }; |
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.
Use camel case here