Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const useDocument = (doctype, id) => {
const client = useClient()
return client.getDocumentFromState(doctype, id)
}
const BundleInfo = withRouter(({ bundle, router }) => {
const { t } = useI18n()
const client = useClient()
const { isMobile } = useBreakpoints()
if (!bundle) {
return null
}
const [showingActionsMenu, showActionsMenu, hideActionsMenu] = useToggle(
false
)
const [showingRename, showRename, hideRename] = useToggle(false)
const goToRecurrenceRoot = useCallback(() => router.push('/recurrence'), [
router
])
const handleOpenRename = useCallback(() => {
showRename()
const TransactionCategoryEditor = props => {
const client = useClient()
const { transaction, beforeUpdate, afterUpdate, onCancel, modal } = props
const handleSelect = async category => {
if (beforeUpdate) {
await beforeUpdate()
}
const newTransaction = await updateTransactionCategory(
client,
transaction,
category
)
if (afterUpdate) {
await afterUpdate(newTransaction)
}
}
const RenameBundleModal = ({ bundle, dismissAction }) => {
const client = useClient()
const { t } = useI18n()
const renameInputRef = useRef()
const handleRename = async () => {
try {
await renameRecurrenceManually(
client,
bundle,
renameInputRef.current.value
)
dismissAction()
Alerter.success(t('Recurrence.rename.save-success'))
} catch (e) {
Alerter.error(t('Recurrence.rename.save-error'))
}
}
const TransactionRecurrenceEditor = ({
transaction,
beforeUpdate,
afterUpdate
}) => {
const { t } = useI18n()
const client = useClient()
const current = transaction.recurrence.data
const currentId = current && current._id
const recurrenceCol = useQuery(recurrenceConn.query, recurrenceConn)
const { data: allRecurrences } = recurrenceCol
const recurrenceOptions = useMemo(
() =>
allRecurrences
? [makeNewRecurrenceOption(t)].concat(
allRecurrences.map(makeOptionFromRecurrence)
)
: null,
[allRecurrences, t]
)
for (let day of days) {
const newTransactionsOfDay = byDay[day]
curBundles = updateRecurrences(bundles, newTransactionsOfDay, rules)
}
return curBundles
}, [bundles, newTransactions, rules])
const finalBundles = useMemo(() => {
const filteredBundles = updatedBundles.filter(
makeTextFilter(bundleFilter, bundle => bundle.ops[0].label)
)
const sortedBundles = sortBy(filteredBundles, bundle => bundle.ops[0].label)
return sortedBundles
}, [updatedBundles, bundleFilter])
const client = useClient()
const [savingBundles, setSavingBundles] = useState()
const [resettingBundles, setResettingBundles] = useState()
const handleSaveBundles = useCallback(
async function() {
setSavingBundles(true)
try {
await saveHydratedBundles(client, finalBundles)
} catch (error) {
Alerter.error(error.message)
} finally {
setSavingBundles(false)
}
},
[finalBundles, client]
)