Skip to content

Commit

Permalink
prep alternative onboarding flow
Browse files Browse the repository at this point in the history
  • Loading branch information
wbglaeser committed Jun 21, 2024
1 parent 49d9f53 commit e1cd457
Show file tree
Hide file tree
Showing 12 changed files with 73 additions and 20 deletions.
15 changes: 15 additions & 0 deletions public/assets/data/profile-sections/children.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,21 @@
"title": "Do you want to add information on your children?",
"datatype": "class",
"objectClass": "ff:Child"
},
{
"datafield": "ff:hasIncomeBrutto",
"title": "What is your income BEFORE taxes?",
"datatype": "integer"
},
{
"datafield": "ff:hasIncomeNetto",
"title": "What is your income AFTER taxes?",
"datatype": "integer"
},
{
"datafield": "ff:hasEducationLevel",
"title": "What is your highest level of eduction?",
"datatype": "string"
}
]
}
13 changes: 9 additions & 4 deletions public/assets/data/profile-sections/ff:Child.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
{
"id": "education",
"id": "ff:Child",
"title": "Child",
"fields": [
{
"datafield": "ff:hasEducationLevel",
"title": "What is your highest level of eduction?",
"datatype": "string"
"datafield": "ff:hasIncomeBrutto",
"title": "What is your income BEFORE taxes?",
"datatype": "integer"
},
{
"datafield": "ff:hasIncomeNetto",
"title": "What is your income AFTER taxes?",
"datatype": "integer"
}
]
}
10 changes: 5 additions & 5 deletions src/models/UserModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,22 +90,22 @@ function updateOrAddField(data, value, datafield, entityData) {
return true;
}

if (data['@id'] === entityData.parentData.id && data['@type'] === entityData.parentData.type) {
if (Array.isArray(data[entityData.parentData.datafield])) {
for (let item of data[entityData.parentData.datafield]) {
if (data['@id'] === entityData.parentId && data['@type'] === entityData.parentType) {
if (Array.isArray(data[entityData.parentDatafield])) {
for (let item of data[entityData.parentDatafield]) {
if (updateOrAddField(item, value, datafield, entityData)) {
return true;
}
}
} else {
data[entityData.parentData.datafield] = [];
data[entityData.parentDatafield] = [];
}
const newChild = {
'@id': entityData.id,
'@type': entityData.type,
[datafield]: value,
};
data[entityData.parentData.datafield].push(newChild);
data[entityData.parentDatafield].push(newChild);
return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const useInitializeProfileSections = () => {
};
useProfileInputSectionStore
.getState()
.initialiseSection(newDictEntry.id, newDictEntry.nextId, i === 0);
.initialiseSection(newDictEntry.id, newDictEntry.nextId, 'onboarding', i === 0);
});
};
};
Expand Down
10 changes: 8 additions & 2 deletions src/screens/profile-section/ProfileSectionScreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ const ProfileSectionScreen = () => {
const filePath = `assets/data/profile-sections/${id}.json`;
try {
const newProfileSectionData = await readJson(filePath);
newProfileSectionData.entityData = entityData;
newProfileSectionData.fields.map((field) => {
field.nestedEntityData = null;
return field;
});
setProfileSectionData(newProfileSectionData);
} catch (error) {
console.error('Failed to fetch profile input screen data:', error);
Expand All @@ -40,9 +45,10 @@ const ProfileSectionScreen = () => {
<>
<ProfileSectionContext title={profileSectionData.title} infoBox={id === 'about-you'}/>
{!completed ?
(<ProfileSectionList profileSectionData={profileSectionData} entityData={entityData}
(<ProfileSectionList profileSectionData={profileSectionData}
setProfileSectionData={setProfileSectionData}
setCompleted={setCompleted}/>)
: (<ProfileSectionCompleted title={profileSectionData.title} id={id} entityData={entityData}/>)
: (<ProfileSectionCompleted profileSectionData={profileSectionData}/>)
}
</>)
:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import ClearIcon from '@mui/icons-material/Clear';
import ButtonBase from "@mui/material/ButtonBase";
import {useNavigate} from "react-router-dom";

const ProfileSectionClass = ({profileSectionField, entityData}) => {
const ProfileSectionClass = ({profileSectionField, setProfileSectionData,entityData}) => {
const navigate = useNavigate();
const [objectsMap, setObjectsMap] = useState({
index: 0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ import {green, yellow} from "@mui/material/colors";
import SentimentSatisfiedOutlinedIcon from "@mui/icons-material/SentimentSatisfiedOutlined";
import readJson from "../../../utilities/readJson";

const ProfileSectionCompleted = ({title, id, entityData}) => {
const ProfileSectionCompleted = ({profileSectionData}) => {
const { title, id, entityData } = profileSectionData
const [nextSectionData, setNextSectionData] = useState(null);
const sectionStatus = useProfileInputSectionStore((state) => state.sections);
const completedSections = sectionStatus.reduce((acc, section) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const ProfileSectionField = ({
profileSectionField,
entityData,
currentIndex,
setProfileSectionData,
handleConfirm,
handleBack,
handleSkip
Expand Down Expand Up @@ -51,7 +52,8 @@ const ProfileSectionField = ({
profileSectionField.datatype !== 'class' ? (
<ProfileSectionInput value={value} setValue={setValue} error={error}/>
) : (
<ProfileSectionClass profileSectionField={profileSectionField} entityData={entityData}/>
<ProfileSectionClass profileSectionField={profileSectionField}
setProfileSectionData={setProfileSectionData} entityData={entityData}/>
)
}
</VStack>
Expand Down
6 changes: 3 additions & 3 deletions src/screens/profile-section/components/ProfileSectionList.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import ProfileSectionField from "./ProfileSectionField";
import ProfileCompletionBar from "./ProfileCompletionBar";
import useCompleteSection from "../hooks/useCompleteSection";

const ProfileSectionList = ({profileSectionData, entityData, setCompleted}) => {
const ProfileSectionList = ({profileSectionData, setProfileSectionData, setCompleted}) => {
const [currentIndex, setCurrentIndex] = useState(0);
const handleCompleteSection = useCompleteSection(profileSectionData.id);

Expand All @@ -22,7 +22,6 @@ const ProfileSectionList = ({profileSectionData, entityData, setCompleted}) => {
if (currentIndex > 0) {
setCurrentIndex(currentIndex - 1);
} else {
// Handle the case when all sections are completed
console.log('All sections completed');
}
};
Expand All @@ -31,12 +30,12 @@ const ProfileSectionList = ({profileSectionData, entityData, setCompleted}) => {
if (currentIndex < profileSectionData.fields.length - 1) {
setCurrentIndex(currentIndex + 1);
} else {
// Handle the case when all sections are completed
console.log('All sections completed');
}
};

const currentSection = profileSectionData.fields[currentIndex];
const entityData = profileSectionData.fields[currentIndex].nestedEntityData || profileSectionData.entityData

return (
<VStack sx={{width: '100%', paddingTop: '50px'}} gap={3}>
Expand All @@ -45,6 +44,7 @@ const ProfileSectionList = ({profileSectionData, entityData, setCompleted}) => {
<ProfileSectionField profileSectionField={currentSection}
entityData={entityData}
currentIndex={currentIndex}
setProfileSectionData={setProfileSectionData}
handleConfirm={handleConfirm}
handleBack={handleBack}
handleSkip={handleSkip}/>
Expand Down
1 change: 1 addition & 0 deletions src/screens/profile-section/hooks/useAddProfileField.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ function useAddProfileField(value, datafield, entityData) {
UserModel.setField(activeUserId, value, datafield, entityData);
resolve();
} catch (error) {
console.log('Error adding profile field')
reject(error);
}
});
Expand Down
6 changes: 6 additions & 0 deletions src/screens/profile-section/hooks/useUpdateProfileSection.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
const useUpdateProfileSection = (setProfileSectionData) => {


};

export default useUpdateProfileSection;
21 changes: 19 additions & 2 deletions src/storage/zustand.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export const useProfileInputSectionStore = create((set) => ({
console.log('STATE UPDATE: We are resetting the section store');
set((state) => ({ activeSection: 'about-you', sections: [] }));
},
initialiseSection: (id, nextId) => {
initialiseSection: (id, nextId, sectionType) => {
console.log(
'STATE UPDATE: We are adding a new section to the sections store'
);
Expand All @@ -24,12 +24,17 @@ export const useProfileInputSectionStore = create((set) => ({
console.log('Section already exists, not adding:', id);
return state; // No state update if the section exist
}
const newSection = { id, next: nextId, completed: false };
const newSection = { id, next: nextId, sectionType: sectionType, completed: false };
return { sections: [...state.sections, newSection] };
});
},
updateCompletedSections: (id) => {
console.log('STATE UPDATE: We are updating the completed sections: id', id);
const sectionExists = useProfileInputSectionStore.getState().sections.some(section => section.id === id);
if (!sectionExists) {
return;
}

let nextSection;
set((state) => ({
sections: state.sections.map((section) => {
Expand All @@ -44,6 +49,18 @@ export const useProfileInputSectionStore = create((set) => ({
},
}));

export const useProfileSectionStore = create((set) => ({
profileSectionData: {},
initializeProfileSectionData: (newProfileSectionData) => {
console.log('STATE UPDATE: We are initializing the profile section data');
set((state) => ({ profileSectionData: newProfileSectionData }));
},
updateProfileSectionData: (newProfileSectionData) => {
console.log('STATE UPDATE: We are updating the profile section data');
set((state) => ({ profileSectionData: newProfileSectionData }));
},
}));

export const useMetadataStore = create((set) => ({
metadata: {},
updateMetadata: (newMetadata) => {
Expand Down

0 comments on commit e1cd457

Please sign in to comment.