-
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.
- Loading branch information
Showing
3 changed files
with
104 additions
and
1 deletion.
There are no files selected for viewing
50 changes: 50 additions & 0 deletions
50
viestinvalitys-raportointi/src/app/lahetys/[tunniste]/VastaanottajaHaku.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,50 @@ | ||
'use client'; | ||
import { FormControl, FormLabel, InputLabel, MenuItem, Select, TextField } from '@mui/material'; | ||
import { usePathname, useRouter, useSearchParams } from 'next/navigation'; | ||
import { useDebouncedCallback } from 'use-debounce'; | ||
import { useCallback } from 'react'; | ||
|
||
export default function VastaanottajaHaku() { | ||
const router = useRouter() | ||
const pathname = usePathname() | ||
const searchParams = useSearchParams() | ||
|
||
const { replace } = useRouter(); | ||
|
||
// lisätään hakuparametreihin uusi key-value-pari | ||
const createQueryString = useCallback( | ||
(name: string, value: any) => { | ||
const params = new URLSearchParams(searchParams?.toString() || '') | ||
params.set(name, value) | ||
|
||
return params.toString() | ||
}, | ||
[searchParams] | ||
) | ||
|
||
// päivitetään 3s viiveellä hakuparametrit | ||
const handleTypedSearch = useDebouncedCallback((term) => { | ||
const params = new URLSearchParams(searchParams?.toString() || ''); | ||
if (term) { | ||
params.set('hakusana', term); | ||
} else { | ||
params.delete('hakusana'); | ||
} | ||
replace(`${pathname}?${params.toString()}`); | ||
}, 3000); | ||
|
||
return ( | ||
<FormControl fullWidth> | ||
<FormLabel>Hae vastaanottajia</FormLabel> | ||
<TextField | ||
id="hakusana" | ||
variant="outlined" | ||
disabled | ||
placeholder={'Hae nimellä tai sähköpostiosoitteella'} | ||
onChange={(e) => { | ||
handleTypedSearch(e.target.value); | ||
}} | ||
defaultValue={searchParams?.get('hakutermi')?.toString()}/> | ||
</FormControl> | ||
); | ||
} |
50 changes: 50 additions & 0 deletions
50
viestinvalitys-raportointi/src/app/lahetys/[tunniste]/Vastaanottajat.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,50 @@ | ||
'use client' | ||
import { DataGrid, GridColDef } from "@mui/x-data-grid"; | ||
import { VastaanotonTila, Vastaanottaja } from "../../lib/types"; | ||
import { getLahetysStatus } from "../../lib/util"; | ||
import { Box, Table, TableBody, TableCell, TableContainer, TableHead, TableRow } from "@mui/material"; | ||
import { StatusIcon } from "@/app/components/LahetysStatus"; | ||
|
||
const lahetyksenStatus = (tila: VastaanotonTila): string => { | ||
const status = 'Lähetys ' + getLahetysStatus([tila]) | ||
return status | ||
} | ||
|
||
const toiminnot = (tila: VastaanotonTila): string => { | ||
if(getLahetysStatus([tila])==='epäonnistui') { | ||
return 'Lähetä uudelleen' | ||
} | ||
return '' | ||
} | ||
|
||
const VastaanottajatTable = ({vastaanottajat}: {vastaanottajat: Vastaanottaja[]}) => { | ||
return ( | ||
<TableContainer sx={{ maxHeight: 440 }}> | ||
<Table | ||
stickyHeader | ||
aria-label="Vastaanottajat" | ||
> | ||
<TableHead> | ||
<TableRow> | ||
<TableCell>Nimi</TableCell> | ||
<TableCell>Sähköposti</TableCell> | ||
<TableCell>Tila</TableCell> | ||
<TableCell>Toiminnot</TableCell> | ||
</TableRow> | ||
</TableHead> | ||
<TableBody> | ||
{vastaanottajat | ||
.map((row) => ( | ||
<TableRow key={row.tunniste}> | ||
<TableCell>{row.nimi}</TableCell> | ||
<TableCell>{row.sahkoposti}</TableCell> | ||
<TableCell><Box display="flex" alignItems="center"><StatusIcon status={lahetyksenStatus(row.tila)} /> {lahetyksenStatus(row.tila)}</Box></TableCell> | ||
<TableCell>{toiminnot(row.tila)}</TableCell> | ||
</TableRow> | ||
))} | ||
</TableBody> | ||
</Table> | ||
</TableContainer> | ||
)} | ||
|
||
export default VastaanottajatTable |
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