-
Notifications
You must be signed in to change notification settings - Fork 1
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
Feature/create project form #279
Open
Primis1
wants to merge
21
commits into
develop
Choose a base branch
from
feature/create-project-form
base: develop
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 20 commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
c5d9f5c
add init forms
Primis1 af6c959
add: managa project settings form layout, fix: specialist detailed card
Primis1 5d750d2
add; layout for two forms, querries for skills and professions
Primis1 f0afa7f
fix: attributes query, form layout
Primis1 d874e1b
add: form-create-project/specialist, direction query
Primis1 251d1d0
add: contacts, POST query in project API
Primis1 4f7534e
add: not working contacts
Primis1 c414ae3
add: contact fields in request;
Primis1 3894094
fix: two forms now one
Primis1 1a218f3
fix: form-error, page layout
Primis1 c0f5ed2
add: separate rows for contacts.
Primis1 299e72c
Merge branch 'feature/create-project' into feature/new-create-project
Primis1 0069b55
fix: form, query; rm: duplicate contacts component, Attributes query
Primis1 fef6358
add: contacts, forms functionality; remove: attributes query;
Primis1 d00ec31
add: project-speciality with react hook form; refactor: component's a…
Primis1 56c9b85
fix: reload, component structure
Primis1 9322662
add: project specialists slice; rm: unused components
Primis1 0448f1c
fix: toggler, remove function, skill-types, reset function
Primis1 6baad6f
add: contacts global storage, date converter
Primis1 0f77440
fix merge conflict
Primis1 36a31be
feat(features): add create-project feature
makc-anisimov 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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
161 changes: 161 additions & 0 deletions
161
src/entities/add-proejct-specialists/add-project-speciality.tsx
This file contains 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,161 @@ | ||
import React from 'react'; | ||
import styles from './add-specialty.module.scss'; | ||
import { LEVEL } from '@/utils/constants'; | ||
import { TProfession, TSkills } from '@/shared/types/specialty'; | ||
import IconPlus from '@/shared/assets/icons/plus-large.svg'; | ||
import { AddSpecialtyProps } from './types'; | ||
import SelectWithSearch from '@/shared/ui/select-search/select-search'; | ||
import { | ||
getLevelName, | ||
getSkills, | ||
transformProfessions, | ||
} from '@/utils/specialists-functions'; | ||
import { MainButton } from '@/shared/ui'; | ||
import { MultiSelectInput } from '@/shared/ui/multi-select-input/multi-select-input'; | ||
|
||
import { | ||
useForm, | ||
Controller, | ||
} from 'react-hook-form'; | ||
|
||
export const AddProjectSpeciality: React.FC<AddSpecialtyProps> = ({ | ||
professions, | ||
allSkills, | ||
handleAddSpecialty, | ||
}) => { | ||
const { control, handleSubmit, reset, watch } = useForm({ | ||
mode: 'onChange', | ||
}); | ||
|
||
// Watching form fields for real-time values | ||
const selectedProfession = watch('profession'); | ||
const selectedLevel = watch('level'); | ||
const selectedSkills = watch('skills'); | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
const onSubmit: any = (data: { | ||
profession: TProfession; | ||
level: number; | ||
skills: TSkills[]; | ||
}) => { | ||
const { profession, level, skills } = data; | ||
handleAddSpecialty({ | ||
profession, | ||
level, | ||
skills, | ||
}); | ||
reset({ | ||
profession: null, | ||
level: null, | ||
skills: [], | ||
}); | ||
}; | ||
|
||
const handleResetForm = () => { | ||
reset({ | ||
profession: null, | ||
level: null, | ||
skills: [], | ||
}); | ||
}; | ||
|
||
// Utilizing the watched values for field validation | ||
const isFieldsNotFill = () => { | ||
return ( | ||
selectedProfession === null || | ||
selectedLevel === null || | ||
selectedSkills?.length === 0 | ||
); | ||
}; | ||
|
||
interface MultiSelectItem { | ||
label: string; | ||
value: number; // Adjust based on your actual value type | ||
} | ||
|
||
return ( | ||
<div className={styles.addSpecialty}> | ||
<Controller | ||
name="profession" | ||
control={control} | ||
rules={{ required: true }} | ||
render={({ field }) => ( | ||
<SelectWithSearch | ||
label="Специальность" | ||
options={transformProfessions(professions)} | ||
selectedValue={field.value?.specialization as unknown as string} | ||
onValueChange={(value) => | ||
field.onChange( | ||
professions.find((p) => p.specialization === value) | ||
) | ||
} | ||
/> | ||
)} | ||
/> | ||
|
||
<Controller | ||
name="level" | ||
control={control} | ||
rules={{ required: true }} | ||
render={({ field }) => ( | ||
<SelectWithSearch | ||
label="Уровень квалификации" | ||
options={LEVEL} | ||
selectedValue={getLevelName(field.value)} | ||
onValueChange={(value) => | ||
field.onChange( | ||
LEVEL.find((lvl) => lvl.value === value)?.level as number | ||
) | ||
} | ||
/> | ||
)} | ||
/> | ||
|
||
<Controller | ||
name="skills" | ||
control={control} | ||
rules={{ validate: (value) => value.length > 0 }} | ||
render={({ field }) => ( | ||
<MultiSelectInput | ||
width="100%" | ||
name="select-skills" | ||
label="Навыки" | ||
description="Выберите не более 15 навыков" | ||
maxSelections={15} | ||
isSearchable | ||
options={getSkills(allSkills)} | ||
values={getSkills(field.value)} | ||
onChange={(item: MultiSelectItem[]) => | ||
field.onChange( | ||
item.map(({ label, value }) => ({ | ||
name: label, | ||
id: value, | ||
})) | ||
) | ||
} | ||
/> | ||
)} | ||
/> | ||
|
||
<div className={styles.addSpecialty__buttons}> | ||
<MainButton | ||
IconLeft={IconPlus} | ||
variant="secondary" | ||
width="regular" | ||
onClick={handleSubmit(onSubmit)} | ||
type="button" | ||
disabled={isFieldsNotFill()}> | ||
Добавить | ||
</MainButton> | ||
|
||
<MainButton | ||
className={styles.addSpecialty__resetButton} | ||
type="reset" | ||
variant="trivial" | ||
onClick={handleResetForm} | ||
width="min"> | ||
Сбросить | ||
</MainButton> | ||
</div> | ||
</div> | ||
); | ||
}; |
2 changes: 1 addition & 1 deletion
2
...i/add-specialty/add-specialty.module.scss → ...jct-specialists/add-specialty.module.scss
This file contains 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
File renamed without changes.
This file contains 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,27 @@ | ||
@import 'src/shared//style/variables.scss'; | ||
|
||
.addSpecialty { | ||
width: 100%; | ||
display: flex; | ||
flex-direction: column; | ||
gap: 8px; | ||
&__buttons { | ||
display: flex; | ||
justify-content: space-between; | ||
flex-direction: row; | ||
margin-top: 16px; | ||
} | ||
&__resetButton { | ||
cursor: pointer; | ||
background: none; | ||
padding: 0; | ||
color: $--bg-accent-default; | ||
font-family: $--open-sans-font; | ||
font-size: 16px; | ||
font-style: normal; | ||
font-weight: 400; | ||
line-height: 24px; /* 150% */ | ||
letter-spacing: 0.25px; | ||
border: none; | ||
} | ||
} |
This file contains 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 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,9 @@ | ||
import { TProfession, TSkills, TSpeciality } from '@/shared/types/specialty'; | ||
|
||
export type AddSpecialtyProps = { | ||
professions: TProfession[]; | ||
allSkills: TSkills[]; | ||
isLoadingAddSpecialty: boolean; | ||
handleAddSpecialty: (data: TSpeciality) => void; | ||
isSuccessAddSpecialty: boolean; | ||
}; |
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.
Поправить отступы