Skip to content

Commit

Permalink
Merge pull request #276 from aso1124/audit-log-bug
Browse files Browse the repository at this point in the history
Audit log bug
  • Loading branch information
aso1124 authored May 22, 2024
2 parents de5676c + 6599507 commit 7d1940f
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 33 deletions.
26 changes: 16 additions & 10 deletions src/components/audit-log/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,17 +40,23 @@ const AuditLog = ({ flowId, accountId }) => {
<div className="audit-logs-header">
<HeadingText type={HeadingText.TYPE.HEADING_2}>Audit Log</HeadingText>
</div>
<div className="items">
{logs.reverse().map(({ id, user, timestamp }) => (
<div key={id} className="item">
<div className="line">
<span className="title">{user?.name}</span>
<span>({user?.email})</span>
{logs ? (
<div className="items">
{logs?.reverse().map(({ id, user, timestamp }) => (
<div key={id} className="item">
<div className="line">
<span className="title">{user?.name}</span>
<span>({user?.email})</span>
</div>
<div className="line light">{formatTimestamp(timestamp)}</div>
</div>
<div className="line light">{formatTimestamp(timestamp)}</div>
</div>
))}
</div>
))}
</div>
) : (
<HeadingText type={HeadingText.TYPE.HEADING_4}>
No logs found
</HeadingText>
)}
</div>
);
};
Expand Down
43 changes: 20 additions & 23 deletions src/hooks/use-flow-writer/index.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,25 @@
import { useEffect } from 'react';
import {
AccountStorageMutation,
AccountStorageQuery,
useAccountStorageMutation,
} from 'nr1';
import { useCallback } from 'react';
import { AccountStorageMutation, AccountStorageQuery } from 'nr1';

import { NERD_STORAGE } from '../../constants';

const useFlowWriter = ({ accountId, user }) => {
const [write, { data, error: writeError }] = useAccountStorageMutation({
actionType: useAccountStorageMutation.ACTION_TYPE.WRITE_DOCUMENT,
collection: NERD_STORAGE.FLOWS_COLLECTION,
accountId,
});
const write = useCallback(async ({ documentId, document }) => {
const { data: flowData, error: flowWriteError } =
await AccountStorageMutation.mutate({
actionType: AccountStorageMutation.ACTION_TYPE.WRITE_DOCUMENT,
collection: NERD_STORAGE.FLOWS_COLLECTION,
accountId,
documentId,
document: document,
});

useEffect(() => {
const writeToLog = async (documentId) => {
if (flowWriteError) {
console.error(flowWriteError);
return;
}

if (flowData) {
const { data: logsData, error: logReadError } =
await AccountStorageQuery.query({
accountId,
Expand All @@ -40,17 +44,10 @@ const useFlowWriter = ({ accountId, user }) => {
],
},
});
};

const { nerdStorageWriteDocument: { id } = {} } = data || {};
if (id) writeToLog(id);
}, [data]);

useEffect(() => {
if (writeError) console.error('Error writing flow', writeError);
}, [writeError]);
}
}, []);

return { write, data };
return { write };
};

export default useFlowWriter;

0 comments on commit 7d1940f

Please sign in to comment.