import React, { useState } from 'react'; import { TypeInputProps } from './TypeInput'; import { ObjectId } from 'bson'; import { Button, Col, Input, Row } from 'antd'; import { ClearOutlined, ReloadOutlined } from '@ant-design/icons'; export const ObjectIdInput = ({ property, defaultValue, set, extraProps, isPrimary }: TypeInputProps) => { const [_, setReset] = useState(0); const [value, setValue] = useState(defaultValue ? (defaultValue as ObjectId).toString() : null); const onChange = (value: string) => { setValue(value); if (ObjectId.isValid(value)) { set(new ObjectId(value)); } else { set(null); } }; return ( onChange(v.target.value)} placeholder={property.optional ? 'null' : undefined} status={ (value === null && property.optional) || (value !== null && ObjectId.isValid(value)) ? '' : 'error' } /> {property.optional ? ( ) : null} ); };