quintodrome/ui/src/common/Writable.js

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

23 lines
535 B
JavaScript
Raw Normal View History

import { cloneElement, Children, isValidElement } from 'react'
2020-06-05 06:22:31 -08:00
export const isWritable = (owner) => {
return (
localStorage.getItem('username') === owner ||
localStorage.getItem('role') === 'admin'
)
}
export const isReadOnly = (owner) => {
return !isWritable(owner)
}
export const Writable = (props) => {
const { record = {}, children } = props
2020-06-05 06:22:31 -08:00
if (isWritable(record.owner)) {
return Children.map(children, (child) =>
isValidElement(child) ? cloneElement(child, props) : child
)
2020-06-05 06:22:31 -08:00
}
return null
}