mirror of
https://github.com/nowcommunity/nowdatabase.git
synced 2026-10-12 19:13:52 +03:00
fix lint
This commit is contained in:
@@ -59,8 +59,7 @@ router.put(
|
||||
editedPerson.user_id &&
|
||||
editedPerson.now_user_group &&
|
||||
validUserGroups.includes(editedPerson.now_user_group)
|
||||
)
|
||||
{
|
||||
) {
|
||||
await writeUserGroup(editedPerson.user_id, editedPerson.now_user_group as UserGroup)
|
||||
}
|
||||
|
||||
|
||||
@@ -8,28 +8,28 @@ export const writePerson = async (person: EditDataType<PersonDetailsType>) => {
|
||||
const allowedColumns = getFieldsOfTables(['com_people'])
|
||||
const filteredPerson = filterAllowedKeys(person, allowedColumns) as Prisma.com_people
|
||||
let personId: string
|
||||
|
||||
|
||||
const isPerson = await getPersonDetails(filteredPerson.initials)
|
||||
|
||||
if (!isPerson) {
|
||||
if (!isPerson) {
|
||||
const newPerson = await nowDb.com_people.create({
|
||||
data: { ...filteredPerson, full_name: `${filteredPerson.first_name} ${filteredPerson.surname}` },
|
||||
})
|
||||
personId = newPerson.initials
|
||||
} else {
|
||||
await nowDb.com_people.update({
|
||||
await nowDb.com_people.update({
|
||||
where: { initials: person.initials },
|
||||
data: {
|
||||
data: {
|
||||
first_name: filteredPerson.first_name,
|
||||
surname: filteredPerson.surname,
|
||||
email: filteredPerson.email,
|
||||
organization: filteredPerson.organization,
|
||||
country: filteredPerson.country,
|
||||
full_name: `${filteredPerson.first_name} ${filteredPerson.surname}` },
|
||||
full_name: `${filteredPerson.first_name} ${filteredPerson.surname}`,
|
||||
},
|
||||
})
|
||||
personId = filteredPerson.initials
|
||||
}
|
||||
}
|
||||
|
||||
return personId
|
||||
}
|
||||
|
||||
|
||||
@@ -5,8 +5,7 @@ import {
|
||||
SpeciesDetailsType,
|
||||
TimeBoundDetailsType,
|
||||
TimeUnitDetailsType,
|
||||
PersonDetailsType,
|
||||
PersonDetails
|
||||
PersonDetailsType,
|
||||
} from '@/shared/types'
|
||||
|
||||
import { MRT_PaginationState } from 'material-react-table'
|
||||
@@ -250,14 +249,13 @@ export const emptyRegion = {
|
||||
} as unknown as RegionDetails
|
||||
|
||||
export const emptyPerson = {
|
||||
initials: '',
|
||||
first_name: '',
|
||||
surname: '',
|
||||
email: '',
|
||||
organization: '',
|
||||
country: ''
|
||||
initials: '',
|
||||
first_name: '',
|
||||
surname: '',
|
||||
email: '',
|
||||
organization: '',
|
||||
country: '',
|
||||
} as unknown as PersonDetailsType
|
||||
|
||||
export const defaultPagination: MRT_PaginationState = { pageIndex: 0, pageSize: 15 }
|
||||
export const defaultPaginationSmall: MRT_PaginationState = { pageIndex: 0, pageSize: 10 }
|
||||
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
import { useParams, useNavigate } from 'react-router-dom'
|
||||
import { useEditPersonMutation, useGetPersonDetailsIdMutation, useGetPersonDetailsQuery } from '../../redux/personReducer'
|
||||
import {
|
||||
useEditPersonMutation,
|
||||
useGetPersonDetailsIdMutation,
|
||||
useGetPersonDetailsQuery,
|
||||
} from '../../redux/personReducer'
|
||||
import { CircularProgress } from '@mui/material'
|
||||
import { DetailView, TabType } from '../DetailView/DetailView'
|
||||
import { PersonTab } from './Tabs/PersonTab'
|
||||
@@ -24,9 +28,9 @@ export const PersonDetails = () => {
|
||||
const id = isUserPage ? user.initials : idFromUrl
|
||||
const isNew = idFromUrl === 'new'
|
||||
|
||||
const { isLoading, isError, data } = useGetPersonDetailsQuery(id!, {skip:isNew})
|
||||
const { isLoading, isError, data } = useGetPersonDetailsQuery(id!, { skip: isNew })
|
||||
const [getPersonDetailsId] = useGetPersonDetailsIdMutation()
|
||||
|
||||
|
||||
useEffect(() => {
|
||||
if (!isUserPage && user.role !== Role.Admin) {
|
||||
// if user has navigated to any person details page through the url, they are redirected to user-page instead
|
||||
@@ -36,26 +40,24 @@ export const PersonDetails = () => {
|
||||
}, [])
|
||||
|
||||
const personExists = async (initials: string) => {
|
||||
try{
|
||||
const isPerson = await getPersonDetailsId(initials).unwrap()
|
||||
if(isPerson) return true
|
||||
return false
|
||||
}catch
|
||||
{
|
||||
return false
|
||||
}
|
||||
try {
|
||||
const isPerson = await getPersonDetailsId(initials).unwrap()
|
||||
if (isPerson) return true
|
||||
return false
|
||||
} catch {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
const onWrite = async (editData: EditDataType<PersonDetailsType>) => {
|
||||
if (!editData.initials) return
|
||||
if (!editData.initials) return
|
||||
try {
|
||||
if (await personExists(editData.initials)) {
|
||||
notify('Initials already exists. Select Edit.', 'error')
|
||||
return
|
||||
}
|
||||
}
|
||||
const { initials } = await editPersonRequest(editData).unwrap()
|
||||
notify('Saved person successfully.')
|
||||
|
||||
if (isUserPage) {
|
||||
setTimeout(() => navigate('/person/user-page'), 15)
|
||||
} else {
|
||||
@@ -68,9 +70,9 @@ export const PersonDetails = () => {
|
||||
}
|
||||
|
||||
if (isError) return <div>Error loading data</div>
|
||||
if (isLoading || !data && !isNew || mutationLoading) return <CircularProgress />
|
||||
if (isLoading || (!data && !isNew) || mutationLoading) return <CircularProgress />
|
||||
|
||||
document.title = isNew ? 'New person' : `User - ${data!.user?.user_name}`
|
||||
document.title = isNew ? 'New person' : `User - ${data!.user?.user_name}`
|
||||
|
||||
const tabs: TabType[] = [
|
||||
{
|
||||
|
||||
@@ -28,7 +28,7 @@ export const PersonTab = () => {
|
||||
const userGroupOptions = ['su', 'eu', 'er', 'pl', 'plp', 'no', 'ro']
|
||||
|
||||
const person = [
|
||||
['Initials', textField('initials', { type: 'text', disabled: !isNew })],
|
||||
['Initials', textField('initials', { type: 'text', disabled: !isNew })],
|
||||
['First Name', textField('first_name')],
|
||||
['Surname', textField('surname')],
|
||||
['Email', textField('email')],
|
||||
|
||||
@@ -19,7 +19,7 @@ const personsApi = api.injectEndpoints({
|
||||
query: id => ({
|
||||
url: `/person/${id}`,
|
||||
}),
|
||||
}),
|
||||
}),
|
||||
editPerson: builder.mutation<PersonDetailsType, EditDataType<PersonDetailsType>>({
|
||||
query: person => ({
|
||||
url: `/person`,
|
||||
@@ -31,4 +31,5 @@ const personsApi = api.injectEndpoints({
|
||||
}),
|
||||
})
|
||||
|
||||
export const { useGetAllPersonsQuery, useGetPersonDetailsQuery, useEditPersonMutation, useGetPersonDetailsIdMutation } = personsApi
|
||||
export const { useGetAllPersonsQuery, useGetPersonDetailsQuery, useEditPersonMutation, useGetPersonDetailsIdMutation } =
|
||||
personsApi
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import { EditDataType, PersonDetailsType } from '../types'
|
||||
import { Validators, validator } from './validator'
|
||||
|
||||
|
||||
export const validatePerson = (
|
||||
editData: EditDataType<PersonDetailsType>,
|
||||
fieldName: keyof EditDataType<PersonDetailsType>
|
||||
@@ -13,14 +12,13 @@ export const validatePerson = (
|
||||
asString: true,
|
||||
minLength: 2,
|
||||
maxLength: 8,
|
||||
},
|
||||
},
|
||||
first_name: {
|
||||
name: 'First Name',
|
||||
required: true,
|
||||
asString: true,
|
||||
minLength: 2,
|
||||
maxLength: 20,
|
||||
|
||||
},
|
||||
surname: {
|
||||
name: 'Surname',
|
||||
@@ -29,7 +27,7 @@ export const validatePerson = (
|
||||
minLength: 2,
|
||||
maxLength: 20,
|
||||
},
|
||||
email: {
|
||||
email: {
|
||||
name: 'Email',
|
||||
required: true,
|
||||
asString: true,
|
||||
@@ -47,7 +45,6 @@ export const validatePerson = (
|
||||
name: 'Country',
|
||||
required: true,
|
||||
},
|
||||
|
||||
}
|
||||
|
||||
return validator<EditDataType<PersonDetailsType>>(validators, editData, fieldName)
|
||||
|
||||
Reference in New Issue
Block a user