Skip to content

Commit

Permalink
Merge pull request #861 from BinaryStudioAcademy/fix/bt-789-lms-data-…
Browse files Browse the repository at this point in the history
…for-onboarding

bt-789: Talent details from LMS are not displayed on the onboarding flow
  • Loading branch information
nikita-remeslov authored Sep 29, 2023
2 parents 1be595f + bb74018 commit 7f16982
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 51 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ import {
import styles from './styles.module.scss';

const ContactsCVStep: React.FC = () => {
const dispatch = useAppDispatch();
const { currentUser } = useAppSelector((state: RootReducer) => state.auth);
const {
fullName,
phone,
Expand All @@ -53,65 +55,52 @@ const ContactsCVStep: React.FC = () => {
cvUrl,
cvName,
} = useAppSelector((state: RootReducer) => state.talentOnBoarding);

const hasChangesInDetails = useAppSelector(
(state: RootReducer) => state.cabinet.hasChangesInDetails,
);

const lmsData = useAppSelector((state: RootReducer) => state.lms.lmsData);

const {
control,
getValues,
handleSubmit,
errors,
setError,
watch,
reset,
clearErrors,
} = useAppForm<ContactsCVStepDto>({
defaultValues: useMemo(
() => ({
fullName,
phone,
defaultValues: useMemo(() => {
const fullNameValue = fullName ?? lmsData?.talent.fullName;
const phoneValue = phone ?? lmsData?.talent.phoneNumber;

return {
fullName: fullNameValue,
phone: phoneValue,
linkedinLink,
photo,
photoUrl,
cv,
cvUrl,
cvName,
}),
[cv, cvName, cvUrl, fullName, linkedinLink, phone, photo, photoUrl],
),
validationSchema: ContactsCVStepValidationSchema,
});

useEffect(() => {
reset({
};
}, [
cv,
cvName,
cvUrl,
fullName,
phone,
linkedinLink,
phone,
photo,
photoUrl,
cv,
cvName,
cvUrl,
});
}, [
fullName,
phone,
linkedinLink,
reset,
photo,
photoUrl,
cv,
cvUrl,
cvName,
]);
lmsData,
]),
validationSchema: ContactsCVStepValidationSchema,
});

const { setSubmitForm } = useFormSubmit();

const dispatch = useAppDispatch();

const { currentUser } = useAppSelector((state: RootReducer) => state.auth);

const watchedValues = watch([
'fullName',
'phone',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import {
useEffect,
useMemo,
} from '~/bundles/common/hooks/hooks.js';
import { actions as lmsActions } from '~/bundles/lms/store/lms.js';
import { actions as cabinetActions } from '~/bundles/profile-cabinet/store/profile-cabinet.js';
import {
Country,
Expand Down Expand Up @@ -59,6 +60,7 @@ const employmentTypeOptions = Object.values(EmploymentType).map((type) => ({
}));

const ProfileStep: React.FC = () => {
const dispatch = useAppDispatch();
const {
profileName,
salaryExpectation,
Expand All @@ -67,7 +69,19 @@ const ProfileStep: React.FC = () => {
experienceYears,
employmentType,
description,
} = useAppSelector((state: RootReducer) => state.talentOnBoarding);
currentUser,
} = useAppSelector((state: RootReducer) => ({
...state.talentOnBoarding,
...state.auth,
}));

useEffect(() => {
if (!currentUser) {
return;
}

void dispatch(lmsActions.getTalentLmsData({ userId: currentUser.id }));
}, [currentUser, dispatch]);

const hasChangesInDetails = useAppSelector(
(state: RootReducer) => state.cabinet.hasChangesInDetails,
Expand Down Expand Up @@ -99,10 +113,6 @@ const ProfileStep: React.FC = () => {

const { setSubmitForm } = useFormSubmit();

const dispatch = useAppDispatch();

const { currentUser } = useAppSelector((state: RootReducer) => state.auth);

const watchedValues = watch([
'profileName',
'salaryExpectation',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,17 @@ const notConsideredOptions = Object.values(NotConsidered).map((option) => ({
const getAuthState = (state: RootReducer): State => state.auth;
const getTalentOnBoardingState = (state: RootReducer): UserDetails =>
state.talentOnBoarding;

const SkillsStep: React.FC = () => {
const currentUser = useAppSelector(
(rootState) => getAuthState(rootState).currentUser,
);
const dispatch = useAppDispatch();

const talentLMSProjectInfo = useAppSelector(
(state: RootReducer) => state.lms.lmsData?.project,
);

useEffect(() => {
void dispatch(
talentActions.getTalentDetails({
Expand Down Expand Up @@ -105,36 +110,44 @@ const SkillsStep: React.FC = () => {

const { control, getValues, handleSubmit, errors, reset, watch } =
useAppForm<SkillsStepDto>({
defaultValues: useMemo(
() => ({
defaultValues: useMemo(() => {
const repositoryUrls = talentLMSProjectInfo?.repositoryUrl
? [{ url: talentLMSProjectInfo.repositoryUrl }]
: [];

return {
hardSkills,
englishLevel: englishLevel ?? '',
notConsidered,
preferredLanguages,
projectLinks: projectLinks?.length
? toUrlLinks(projectLinks)
: [{ url: '' }],
}),
[
englishLevel,
hardSkills,
notConsidered,
preferredLanguages,
projectLinks,
],
),
: repositoryUrls,
};
}, [
englishLevel,
hardSkills,
notConsidered,
preferredLanguages,
projectLinks,
talentLMSProjectInfo?.repositoryUrl,
]),
validationSchema: skillsStepValidationSchema,
});

useEffect(() => {
const repositoryUrls = talentLMSProjectInfo?.repositoryUrl
? [{ url: talentLMSProjectInfo.repositoryUrl }]
: [];

reset({
hardSkills,
englishLevel,
notConsidered,
preferredLanguages,
projectLinks: projectLinks?.length
? toUrlLinks(projectLinks)
: [{ url: '' }],
: repositoryUrls,
});
}, [
hardSkills,
Expand All @@ -143,6 +156,7 @@ const SkillsStep: React.FC = () => {
preferredLanguages,
reset,
projectLinks,
talentLMSProjectInfo?.repositoryUrl,
]);

const { setSubmitForm } = useFormSubmit();
Expand Down

0 comments on commit 7f16982

Please sign in to comment.