mirror of https://github.com/msgbyte/tailchat
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
30 lines
721 B
TypeScript
30 lines
721 B
TypeScript
2 years ago
|
import React from 'react';
|
||
2 years ago
|
import {
|
||
|
ReferenceField,
|
||
|
ReferenceFieldProps,
|
||
|
TextField,
|
||
|
useRecordContext,
|
||
|
} from 'react-admin';
|
||
|
|
||
|
const SYSTEM_USERID = '000000000000000000000000';
|
||
2 years ago
|
|
||
|
export const UserField: React.FC<Omit<ReferenceFieldProps, 'reference'>> =
|
||
|
React.memo((props) => {
|
||
2 years ago
|
const record = useRecordContext(props);
|
||
|
if (props.source && record) {
|
||
|
if (record[props.source] === SYSTEM_USERID) {
|
||
|
return <div>System</div>;
|
||
|
}
|
||
|
}
|
||
|
|
||
2 years ago
|
return (
|
||
|
<ReferenceField link="show" {...props} reference="users">
|
||
2 years ago
|
<>
|
||
|
<TextField source="nickname" />
|
||
|
(<TextField source="email" />)
|
||
|
</>
|
||
2 years ago
|
</ReferenceField>
|
||
|
);
|
||
|
});
|
||
|
UserField.displayName = 'UserField';
|