-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #34 from ubc-biztech/registration-user-popup
Style and Create User Pop up Modal in Registration Page #33
- Loading branch information
Showing
8 changed files
with
404 additions
and
26 deletions.
There are no files selected for viewing
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
75 changes: 75 additions & 0 deletions
75
src/components/RegistrationTable/editCellPopUp.tsx/userInfo.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,75 @@ | ||
import React, { ChangeEvent, useEffect, useState } from 'react' | ||
import { Row, Table } from "@tanstack/react-table" | ||
import { Attendee } from "../columns" | ||
import SelectCell from './userPopupEdit' | ||
import { ColumnMeta } from '../columns' | ||
|
||
interface EditCellProps { | ||
row: Row<Attendee>, | ||
table: Table<Attendee> | ||
} | ||
|
||
const UserInfo: React.FC<EditCellProps> = ({ row, table }) => { | ||
const [fieldLabels, setFieldLabels] = useState<{ [key: string]: string }>({}); | ||
const [dropDownList, setDropDownList] = useState<{ [key: string]: string[] }>({}); | ||
|
||
useEffect(() => { | ||
const generateFieldLabels = () => { | ||
const columns = table.getAllColumns(); | ||
const labels: { [key: string]: string } = {}; | ||
|
||
columns.forEach((column) => { | ||
const accessorKey = column.id; | ||
const header = column.columnDef.header; | ||
|
||
if (accessorKey && typeof header === 'string') { | ||
labels[accessorKey] = header; | ||
} | ||
}); | ||
return labels; | ||
}; | ||
|
||
setFieldLabels(generateFieldLabels()); | ||
|
||
const generateDropDownList = () => { | ||
const columns = table.getAllColumns(); | ||
const options: { [key: string]: string[] } = {}; | ||
columns.forEach(column => { | ||
// had to import meta as Column Meta or else encountered errors | ||
const meta = column.columnDef.meta as ColumnMeta | undefined; | ||
|
||
if (meta?.type === 'select') { | ||
options[column.id] = meta.options?.map(opt => opt.value) || []; | ||
} | ||
}); | ||
|
||
return options; | ||
}; | ||
|
||
setDropDownList(generateDropDownList()); | ||
|
||
}, [table]); | ||
|
||
const fieldsToDisplay = Object.keys(row.original).filter(key => key !== 'shouldNotDisplay' && key !== 'id' && key != 'dynamicResponses'); | ||
|
||
|
||
return ( | ||
<div className="text-white gap-4 m-3 grid auto-cols-fr sm:grid-cols-2"> | ||
{fieldsToDisplay?.map((key) => ( | ||
<div key={key}> | ||
<label className="block font-bold text-baby-blue">{fieldLabels[key]}:</label> | ||
{key === 'regStatus' || key === 'appStatus' ? ( | ||
<SelectCell originalValue={row.original[key]} dropDownList={dropDownList[key]}/> | ||
) : key === 'points' ? ( | ||
<SelectCell originalValue={row.original[key]} dropDownList={dropDownList[key]}/> | ||
) : ( | ||
<span>{row.original[key]}</span> | ||
)} | ||
</div> | ||
))} | ||
</div> | ||
) | ||
} | ||
|
||
export default UserInfo | ||
|
57 changes: 57 additions & 0 deletions
57
src/components/RegistrationTable/editCellPopUp.tsx/userPopupEdit.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,57 @@ | ||
import { Select, SelectContent, SelectGroup, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select" | ||
import { Input } from "@/components/ui/input" | ||
import React, { useState } from 'react' | ||
|
||
|
||
interface SelectCellProps { | ||
originalValue: string | number, | ||
dropDownList: string[] | ||
} | ||
|
||
const SelectCell: React.FC<SelectCellProps> = ({ originalValue, dropDownList }) => { | ||
const [value, setValue] = useState(originalValue) | ||
|
||
const onSelectChange = (newValue: string) => { | ||
setValue(newValue) | ||
console.log("TODO - update data") | ||
} | ||
|
||
const handleInputChange = (e: React.ChangeEvent<HTMLInputElement>) => { | ||
setValue(e.target.value); | ||
}; | ||
|
||
|
||
return ( | ||
<div> | ||
{dropDownList ? ( | ||
<Select onValueChange={onSelectChange} defaultValue="Not Found"> | ||
<SelectTrigger className="p3 rounded-none bg-events-active-tab-bg text-white p-0 border-0 border-b-2 border-b-baby-blue"> | ||
<SelectValue> | ||
{value} | ||
</SelectValue> | ||
</SelectTrigger> | ||
<SelectContent className='focus:border-0 bg-white'> | ||
<SelectGroup> | ||
{/* Use the key to access the correct dropDownList */} | ||
{dropDownList.map((item) => ( | ||
<SelectItem key={item} value={item}> | ||
{item} | ||
</SelectItem> | ||
))} | ||
</SelectGroup> | ||
</SelectContent> | ||
</Select> | ||
) : ( | ||
<Input | ||
className="p3 rounded-none bg-events-active-tab-bg text-white p-0 border-0 border-b-2 border-b-baby-blue" | ||
type="number" | ||
value={value} | ||
onChange={handleInputChange} | ||
/> | ||
)} | ||
</div> | ||
); | ||
} | ||
|
||
export default SelectCell; | ||
|
Oops, something went wrong.