Skip to content

Commit

Permalink
Merge pull request #425 from energywebfoundation/fix/mismatch-types-f…
Browse files Browse the repository at this point in the history
…or-newmessage-form

fix(dsb-client-gateway-frontend): fix mismatched types for new message form
  • Loading branch information
vickenliu authored Feb 21, 2024
2 parents a8c70a1 + 07f0fe2 commit 00fd404
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export const NewMessage: FC = () => {
setTransactionId,
} = useNewMessageEffects();

const [formData, setFormData] = useState([]);
const [formData, setFormData] = useState({});
const [errors, setErrors] = useState({});

useEffect(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import {
FormSelectOption,
GenericFormField,
} from '@ddhub-client-gateway-frontend/ui/core';
import { PROPERTIES_KEY } from '@rjsf/utils';

export const fields: { [name: string]: GenericFormField } = {
channel: {
Expand Down Expand Up @@ -43,22 +42,24 @@ export const fields: { [name: string]: GenericFormField } = {
},
};

export const constructDefaultData = (schema: string) => {
export const constructDefaultData = (schema: string): Record<string, any> => {
try {
const jsonSchema = JSON.parse(schema);
const properties = jsonSchema.properties;
if (!properties || Object.keys(properties).length === 0) return [];
console.log('constructDefaultData', properties, jsonSchema);
if (!properties || Object.keys(properties).length === 0) return {};

let data: Record<string, any> = {};
const data: Record<string, any> = {};
for (const key in properties) {
if (properties[key].default) {
if (properties[key].default !== undefined) {
data[key] = properties[key].default;
}
}
console.log('constructDefaultData', data);

return Object.keys(data).length > 0 ? data : [];
return Object.keys(data).length > 0 ? data : {};
} catch (e) {
console.error('constructDefaultData', e);
return [];
return {};
}
};

0 comments on commit 00fd404

Please sign in to comment.