@@ -18,8 +18,20 @@ export const EntrantsColumns: ColumnDef<AdminUser>[] = [
1818 } ,
1919 } ,
2020 {
21- accessorKey : 'contracts ' ,
21+ accessorKey : 'degree ' ,
2222 header : 'Освітній ступінь' ,
23+ sortingFn : ( rowA , rowB ) => {
24+ const getEntrantDegree = ( { contracts } : AdminUser ) => {
25+ if ( contracts . length === 0 ) return '-' ;
26+ return educationalDegreeLabels [
27+ contracts [ 0 ] . degree as EducationalDegree
28+ ] ;
29+ } ;
30+
31+ return getEntrantDegree ( rowA . original ) . localeCompare (
32+ getEntrantDegree ( rowB . original )
33+ ) ;
34+ } ,
2335 cell : ( { row } ) => {
2436 return row . original . contracts . length
2537 ? educationalDegreeLabels [
@@ -31,6 +43,16 @@ export const EntrantsColumns: ColumnDef<AdminUser>[] = [
3143 {
3244 accessorKey : 'fundingSource' ,
3345 header : 'Форма фінансування' ,
46+ sortingFn : ( rowA , rowB ) => {
47+ const getEntrantFundingSource = ( { contracts } : AdminUser ) => {
48+ if ( contracts . length === 0 ) return '-' ;
49+ return FundingSourceLabels [ contracts [ 0 ] . fundingSource as FundingSource ] ;
50+ } ;
51+
52+ return getEntrantFundingSource ( rowA . original ) . localeCompare (
53+ getEntrantFundingSource ( rowB . original )
54+ ) ;
55+ } ,
3456 cell : ( { row } ) => {
3557 return row . original . contracts . length > 0
3658 ? FundingSourceLabels [
@@ -42,6 +64,24 @@ export const EntrantsColumns: ColumnDef<AdminUser>[] = [
4264 {
4365 accessorKey : 'expectedSpecialities' ,
4466 header : 'Спеціальність' ,
67+ sortingFn : ( rowA , rowB ) => {
68+ const getEntrantSpecialities = ( {
69+ contracts,
70+ expectedSpecialities,
71+ } : AdminUser ) => {
72+ if ( contracts . length === 0 ) return '-' ;
73+ return (
74+ contracts . find ( ( contract ) => contract . state === 'APPROVED' )
75+ ?. specialty ||
76+ expectedSpecialities ||
77+ contracts [ 0 ] . specialty
78+ ) ;
79+ } ;
80+
81+ return getEntrantSpecialities ( rowA . original ) . localeCompare (
82+ getEntrantSpecialities ( rowB . original )
83+ ) ;
84+ } ,
4585 cell : ( { row } ) => {
4686 const { contracts, expectedSpecialities } = row . original ;
4787 if ( contracts . length > 0 ) {
@@ -61,8 +101,21 @@ export const EntrantsColumns: ColumnDef<AdminUser>[] = [
61101 } ,
62102 } ,
63103 {
64- accessorKey : 'contracts ' ,
104+ accessorKey : 'status ' ,
65105 header : 'Статус' ,
106+ sortingFn : ( rowA , rowB ) => {
107+ const getEntrantStatus = ( { role, contracts } : AdminUser ) => {
108+ if ( role === 'ADMIN' ) return 'Відсутній' ;
109+ if ( contracts . length === 0 ) return 'Не подано' ;
110+ if ( contracts . some ( ( contract ) => contract . state === 'APPROVED' ) )
111+ return 'Зареєстровано' ;
112+ return 'Подано' ;
113+ } ;
114+
115+ return getEntrantStatus ( rowA . original ) . localeCompare (
116+ getEntrantStatus ( rowB . original )
117+ ) ;
118+ } ,
66119 cell : ( { row } ) => {
67120 const { contracts, role } = row . original ;
68121
@@ -93,4 +146,58 @@ export const EntrantsColumns: ColumnDef<AdminUser>[] = [
93146 ) ;
94147 } ,
95148 } ,
149+ {
150+ accessorKey : 'contractNumber' ,
151+ header : 'Номер' ,
152+ sortingFn : ( rowA , rowB ) => {
153+ const contractADate =
154+ rowA . original . contracts . find (
155+ ( contract ) => contract . state === 'APPROVED'
156+ ) ?. number || '-' ;
157+ const contractBDate =
158+ rowB . original . contracts . find (
159+ ( contract ) => contract . state === 'APPROVED'
160+ ) ?. number || '-' ;
161+
162+ return contractADate . localeCompare ( contractBDate ) ;
163+ } ,
164+ cell : ( { row } ) => {
165+ const { contracts } = row . original ;
166+
167+ const approvedContract = contracts . find (
168+ ( contract ) => contract . state === 'APPROVED'
169+ ) ;
170+
171+ return approvedContract ?. number || '-' ;
172+ } ,
173+ } ,
174+ {
175+ accessorKey : 'contractDate' ,
176+ header : 'Дата' ,
177+ sortingFn : ( rowA , rowB ) => {
178+ const contractADate =
179+ rowA . original . contracts . find (
180+ ( contract ) => contract . state === 'APPROVED'
181+ ) ?. date || '-' ;
182+ const contractBDate =
183+ rowB . original . contracts . find (
184+ ( contract ) => contract . state === 'APPROVED'
185+ ) ?. date || '-' ;
186+
187+ return contractADate
188+ . split ( '.' )
189+ . reverse ( )
190+ . join ( '.' )
191+ . localeCompare ( contractBDate . split ( '.' ) . reverse ( ) . join ( '.' ) ) ;
192+ } ,
193+ cell : ( { row } ) => {
194+ const { contracts } = row . original ;
195+
196+ const approvedContract = contracts . find (
197+ ( contract ) => contract . state === 'APPROVED'
198+ ) ;
199+
200+ return approvedContract ?. date || '-' ;
201+ } ,
202+ } ,
96203] ;
0 commit comments