// src/features/Notes/Notes.js
import React, { useContext, useState } from 'react';
import { HatClient } from '@dataswift/hat-js';
import { appConfig } from '../../app.config';
import AuthContext from "../../components/context/AuthContext";
const [newNote, setNewNote] = useState('');
const authContext = useContext(AuthContext);
// The endpoint to store the Notes data
const notesEndpoint = 'my-notes';
// Create the configuration object to pass the auth token, api version and
// the ssl flag to the HAT-JS
token: authContext.user.token,
apiVersion: appConfig.hatApiVersion,
secure: appConfig.secure,
// Initialize the HatClient with the configuration file
const hat = new HatClient(config);
const handleChange = event => {
setNewNote(event.target.value);
const handleSubmit = event => {
const createData = async () => {
const dateCreated = new Date().toISOString();
// Create the structure for the Note
dateCreated: dateCreated,
// Use the HAT-JS library to create our first data record
const res = await hat.hatData().create(appConfig.namespace, notesEndpoint, body);
console.log(e.cause + e.state)
onSubmit={e => handleSubmit(e)}
onChange={e => handleChange(e)}