2020-06-05 07:45:46 -08:00
|
|
|
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)
|
|
|
|
|
}
|
|
|
|
|
|
2020-11-10 15:27:28 -09:00
|
|
|
export const Writable = (props) => {
|
2020-11-05 10:06:21 -09:00
|
|
|
const { record = {}, children } = props
|
2020-06-05 06:22:31 -08:00
|
|
|
if (isWritable(record.owner)) {
|
2020-06-05 07:45:46 -08:00
|
|
|
return Children.map(children, (child) =>
|
|
|
|
|
isValidElement(child) ? cloneElement(child, props) : child
|
|
|
|
|
)
|
2020-06-05 06:22:31 -08:00
|
|
|
}
|
|
|
|
|
return null
|
|
|
|
|
}
|