Skip to content
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

Made cooperation terms unchangable #2669

Open
wants to merge 5 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/components/active-students/ActiveStudentsBlock.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ const ActiveStudentsBlock = () => {
key={cooperation._id}
lastName={cooperation.user.lastName}
photo={cooperation.user.photo}
subjectName={cooperation.offer.subject.name}
subjectName={cooperation.subject.name}
/>
))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ const AcceptCooperationModal: FC<AcceptCooperationModalProps> = ({
const { closeModal } = useModalContext()
const { checkConfirmation } = useConfirm()
const dispatch = useAppDispatch()
const [minPrice, maxPrice] = minMaxPrice(cooperation.offer.price, 0.25)
const [minPrice, maxPrice] = minMaxPrice(cooperation.price, 0.25)

const needAction = cooperation.user.role !== cooperation.needAction

Expand All @@ -61,9 +61,8 @@ const AcceptCooperationModal: FC<AcceptCooperationModalProps> = ({
})

const updateOffer = useCallback(
() =>
OfferService.updateOffer(cooperation.offer._id, { enrolledUsers: [] }),
[cooperation.offer._id]
() => OfferService.updateOffer(cooperation.offer, { enrolledUsers: [] }),
[cooperation.offer]
)

const onResponse = () => {
Expand Down Expand Up @@ -195,7 +194,7 @@ const AcceptCooperationModal: FC<AcceptCooperationModalProps> = ({
title={t('cooperationsPage.acceptModal.level')}
/>
<TitleWithDescription
description={`${cooperation.offer.price} ${t('common.uah')}`}
description={`${cooperation.price} ${t('common.uah')}`}
style={styles.titleDescription}
title={t('cooperationsPage.acceptModal.price')}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,8 @@ const CooperationCard: FC<CooperationCardProps> = ({
sx
}) => {
const { t } = useTranslation()
const {
user,
offer,
updatedAt,
proficiencyLevel,
price,
status,
needAction
} = cooperation
const { user, updatedAt, proficiencyLevel, price, status, needAction } =
cooperation

const cooperationStatus =
user.role !== needAction && status === StatusEnum.Pending
Expand Down Expand Up @@ -64,12 +57,12 @@ const CooperationCard: FC<CooperationCardProps> = ({
</Box>
</Box>
<SubjectLevelChips
color={offer.category.appearance.color}
color={cooperation.category.appearance.color}
proficiencyLevel={proficiencyLevel}
subject={offer.subject.name}
subject={cooperation.subject.name}
sx={styles.chipBox}
/>
<Typography sx={styles.title}>{cooperation.offer.title}</Typography>
<Typography sx={styles.title}>{cooperation.title}</Typography>
</AppCard>
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,15 @@ export const columns: TableColumn<Cooperation>[] = [
{
label: 'cooperationsPage.tableHeaders.title',
calculatedCellValue: (item: Cooperation) => (
<Typography sx={styles.title}>{item.offer.title}</Typography>
<Typography sx={styles.title}>{item.title}</Typography>
)
},
{
label: 'cooperationsPage.tableHeaders.subject',
calculatedCellValue: (item: Cooperation) => (
<SubjectLevelChips
proficiencyLevel={item.proficiencyLevel}
subject={item.offer.subject.name}
subject={item.subject.name}
sx={styles.chips}
/>
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,10 @@ const MyCooperationsDetails = () => {

const { offer, price } = detailsResponse

const CategoryIcon = getCategoryIcon(offer.category.appearance.icon)
const categoryColor = getValidatedHexColor(offer.category.appearance.color)
const CategoryIcon = getCategoryIcon(detailsResponse.category.appearance.icon)
const categoryColor = getValidatedHexColor(
detailsResponse.category.appearance.color
)

const onHandleClick = () => {
navigate(
Expand All @@ -88,18 +90,16 @@ const MyCooperationsDetails = () => {
authorRole: displayedUser.role[0] as
| UserRoleEnum.Student
| UserRoleEnum.Tutor,
chatId: offer.chatId,
chatId: detailsResponse.chatId,
updateInfo: updateInfo
})

const languages =
offer.languages &&
offer.languages.map((item: string) => (
<Box key={item} sx={style.languageItem}>
<DoneIcon color='success' />
<Typography>{item}</Typography>
</Box>
))
const languages = detailsResponse.languages?.map((item: string) => (
<Box key={item} sx={style.languageItem}>
<DoneIcon color='success' />
<Typography>{item}</Typography>
</Box>
))

const avatarSrc =
displayedUser.photo &&
Expand All @@ -118,7 +118,7 @@ const MyCooperationsDetails = () => {
<Typography sx={style.titles}>
{t('cooperationDetailsPage.title')}
</Typography>
<Typography sx={style.title}>{offer.title}</Typography>
<Typography sx={style.title}>{detailsResponse.title}</Typography>
<Typography sx={style.titles}>
{t(
isTutor
Expand Down Expand Up @@ -167,12 +167,12 @@ const MyCooperationsDetails = () => {
<Box sx={style.subjectContainer}>
<Box sx={style.categoryContainer}>
<CategoryIcon sx={style.iconColor(categoryColor)} />
<Typography>{offer.category.name}</Typography>
<Typography>{detailsResponse.category.name}</Typography>
</Box>
<SubjectLevelChips
color={offer.category.appearance.color}
proficiencyLevel={offer.proficiencyLevel}
subject={offer.subject.name}
color={detailsResponse.category.appearance.color}
proficiencyLevel={detailsResponse.proficiencyLevel}
subject={detailsResponse.subject.name}
/>
</Box>
<Typography sx={style.titles}>
Expand All @@ -181,7 +181,7 @@ const MyCooperationsDetails = () => {
<ShowMoreCollapse
collapsedSize={28}
collapsedTextLength={100}
description={offer.description}
description={detailsResponse.description}
sx={style.aboutCooperation}
withoutTitle
/>
Expand Down
8 changes: 6 additions & 2 deletions src/containers/offer-details/enroll-offer/EnrollOffer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,11 @@ const EnrollOffer: FC<EnrollOfferProps> = ({ offer, enrollOffer }) => {
...data,
receiver: offer.author._id,
receiverRole: offer.authorRole,
offer: offer._id
offer: offer._id,
subject: offer.subject._id,
category: offer.category._id,
description: offer.description,
languages: offer.languages
})
}

Expand All @@ -83,7 +87,7 @@ const EnrollOffer: FC<EnrollOfferProps> = ({ offer, enrollOffer }) => {
const { data, handleInputChange, handleNonInputValueChange, handleSubmit } =
useForm<EnrollOfferForm>({
initialValues: {
proficiencyLevel: offer.proficiencyLevel[0],
proficiencyLevel: offer.proficiencyLevel,
price: offer.price,
info: '',
title: offer.title
Expand Down
41 changes: 23 additions & 18 deletions src/types/cooperation/interfaces/cooperation.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,53 +8,58 @@ import {
UserRoleEnum,
SubjectInterface,
CategoryInterface,
CourseSection
CourseSection,
LanguagesEnum
} from '~/types'

export interface Cooperation extends CommonEntityFields {
offer: Pick<Offer, 'subject' | 'title' | 'category' | 'price' | '_id'>
offer: string
subject: Pick<SubjectInterface, 'name'>
category: CategoryInterface
description: string
languages: LanguagesEnum[]
user: Pick<UserResponse, 'firstName' | 'lastName' | 'photo' | '_id'> & {
role: UserRoleEnum
}
title: Offer['title']
price: Offer['price']
proficiencyLevel: ProficiencyLevelEnum
proficiencyLevel: ProficiencyLevelEnum[]
status: StatusEnum
needAction: UserRoleEnum
sections: CourseSection[]
createdAt: string
updatedAt: string
}

export interface MyCooperationDetails<TOffer extends Offer> {
offer: Pick<
TOffer,
| 'subject'
| 'title'
| 'category'
| 'price'
| '_id'
| 'author'
| 'proficiencyLevel'
| 'description'
| 'languages'
| 'chatId'
>
offer: Pick<TOffer, '_id' | 'author' | 'chatId'>
price: number
title: string
description: string
receiver: UserResponse
receiverRole: UserRoleEnum
languages: string[]
languages: LanguagesEnum[]
chatId: string
author: UserResponse
subject: Pick<SubjectInterface, 'name'>
category: CategoryInterface
proficiencyLevel: ProficiencyLevelEnum
proficiencyLevel: ProficiencyLevelEnum[]
initiator: UserResponse
initiatorRole: UserRoleEnum
status: StatusEnum
needAction: UserRoleEnum
createdAt: string
updatedAt: string
}

export interface CreateCooperationsParams extends EnrollOfferForm {
title: string
offer: string
receiver: string
receiverRole: UserRoleEnum
subject: string
category: string
proficiencyLevel: ProficiencyLevelEnum[]
description: string
languages: LanguagesEnum[]
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Offer, ProficiencyLevelEnum } from '~/types'

export interface EnrollOfferForm extends Pick<Offer, 'price'> {
proficiencyLevel: ProficiencyLevelEnum
proficiencyLevel: ProficiencyLevelEnum[]
info: string
title: string
}
61 changes: 61 additions & 0 deletions tests/test-constants.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
export const getCooperationByIdMockResponse = {
_id: '672fd85a48371231a70da39f',
price: 500,
proficiencyLevel: ['Beginner'],
status: 'active',
needAction: 'tutor',
title: 'Cooperation title',
initiator: { _id: '66fd88ddc84a281ab2f2de93', role: ['tutor'] },
receiver: { _id: '66b0aecdadd1fe775238c7d5', role: ['student'] },
offer: {
_id: '66ec53d40d9d9983a9525421',
author: {
_id: '66a7abbab3168fa64a8f5af1',
firstName: 'John',
lastName: 'Doe',
photo: '1726302583778-pexels-vanessa-garcia-6326377.jpg',
professionalSummary: 'I have 5 years of experience',
averageRating: { student: 0, tutor: 0 },
totalReviews: { student: 0, tutor: 0 }
}
},
description: 'Cooperation description',
languages: ['English'],
subject: { name: 'Web Development' },
category: { appearance: { icon: 'StarRoundedIcon', color: '#607D8B' } },
sections: [],
user: {
_id: '66fd88ddc84a281ab2f2de93',
firstName: 'John',
lastName: 'Doe',
role: 'tutor'
},
createdAt: '2024-09-12T11:28:34.397Z',
updatedAt: '2024-09-12T11:28:34.397Z'
}

export const mockedCooperations = {
items: [
{
_id: '66ec53d40d9d9983a952541',
title: 'Cooperation title',
offer: '66ec53d40d9d9983a952542',
subject: { name: 'Web Development' },
category: { appearance: { icon: 'StarRoundedIcon', color: '#607D8B' } },
description: 'Cooperation description',
languages: ['English'],
user: {
_id: '6565f781b2b2c701e9183cb8',
firstName: 'Jane',
lastName: 'Doe',
photo: 'https://images.unsplash.com/photo-1570295999919-56ceb5ecca61'
},
price: 1800,
proficiencyLevel: ['Beginner'],
status: 'pending',
needAction: 'student',
sections: []
}
],
count: 1
}
Loading
Loading