Skip to content

Commit

Permalink
Refactor model column and add it also to non-admin staff
Browse files Browse the repository at this point in the history
  • Loading branch information
ShootingStar91 committed Aug 7, 2023
1 parent 3028b83 commit 1cb0218
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 12 deletions.
13 changes: 12 additions & 1 deletion client/components/AdminPage/UserTable/deviceModels.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,15 @@ const deviceModels = {
2023: 'Thinkpad L14 gen 3',
}

export default deviceModels
const deviceModelColumn = {
key: 'device_model',
label: 'Device model',
renderCell: ({ deviceGivenAt }) => {
if (!deviceGivenAt) return '-'
const model = deviceModels[new Date(deviceGivenAt).getFullYear()]
if (!model) return 'Not found'
return model
},
}

export default deviceModelColumn
13 changes: 2 additions & 11 deletions client/components/AdminPage/UserTable/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
} from '../../../util/redux/usersReducer'
import dateFormatter from '../../../util/dateFormatter'
import VirtualizedTable from '../../VirtualizedTable'
import deviceModels from './deviceModels'
import deviceModelColumn from './deviceModels'

const UserTable = ({
users, handleAdminNoteClick, handleStaffSettingClick, hiddenColumns, filter,
Expand Down Expand Up @@ -158,16 +158,7 @@ const UserTable = ({
</div>
),
},
{
key: 'device_model',
label: 'Device model',
renderCell: ({ deviceGivenAt }) => {
if (!deviceGivenAt) return '-'
const model = deviceModels[new Date(deviceGivenAt).getFullYear()]
if (!model) return 'Not found'
return model
},
},
deviceModelColumn,
{
key: 'device_returned_at',
label: 'Returned at',
Expand Down
2 changes: 2 additions & 0 deletions client/components/StaffPage/StudentTable/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { useDispatch } from 'react-redux'
import {
Button,
} from 'semantic-ui-react'
import deviceModelColumn from 'Components/AdminPage/UserTable/deviceModels'
import dateFormatter from '../../../util/dateFormatter'
import VirtualizedTable from '../../VirtualizedTable'
import { updateStudentStatus, markStudentEligible } from '../../../util/redux/studentReducer'
Expand Down Expand Up @@ -96,6 +97,7 @@ const StudentTable = ({ students, hiddenColumns }) => {
getCellVal: ({ deviceGivenAt }) => new Date(deviceGivenAt).getTime(),
width: 160,
},
deviceModelColumn,
{
key: 'wants_device',
label: 'Wants device',
Expand Down

0 comments on commit 1cb0218

Please sign in to comment.