Skip to content

Commit

Permalink
removed start to try fixing autofill issue in prod
Browse files Browse the repository at this point in the history
  • Loading branch information
aatbip committed Mar 22, 2024
1 parent e6be715 commit b965ea1
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 78 deletions.
4 changes: 2 additions & 2 deletions src/app/components/EditorInterface.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ const EditorInterface = ({ settings, token }: IEditorInterface) => {
)
const c = template(appData)
setTimeout(() => {
editor?.chain().focus('start').setContent(c).run()
editor?.chain().focus().setContent(c).run()
})
} else {
setTimeout(() => {
Expand All @@ -185,7 +185,7 @@ const EditorInterface = ({ settings, token }: IEditorInterface) => {
.setContent(appState?.appState.originalTemplate as string)
.run()
})
editor?.chain().focus('start').run()
editor?.chain().focus().run()
}
}, [
appState?.appState.selectedClient,
Expand Down
132 changes: 56 additions & 76 deletions src/hooks/useAppData.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,4 @@
import {
createContext,
PropsWithChildren,
useContext,
useEffect,
useMemo,
useState,
} from 'react'
import { createContext, PropsWithChildren, useContext, useMemo } from 'react'
import { useAppState } from '@/hooks/useAppState'
import { IClient, INotification } from '@/types/interfaces'
import Handlebars from 'handlebars'
Expand All @@ -28,90 +21,77 @@ export const useAppData = (template: string) => {

export const AppDataProvider = ({ children }: PropsWithChildren) => {
const appState = useAppState()
const [data, setData] = useState<{
client: IClient | undefined
invoice: { count: number | undefined }
task: { count: number | undefined }
form: { count: number | undefined }
contract: { count: number | undefined }
}>({
client: undefined,
invoice: { count: undefined },
task: { count: undefined },
form: { count: undefined },
contract: { count: undefined },
})
useEffect(() => {
;(() => {
const _client = appState?.appState.clientList.find(
(el) => el.id === (appState?.appState.selectedClient as IClient)?.id,
)
//add comma separator for custom fields
const customFields: any = _client?.customFields

// Iterate through each key in customFields
for (const key in customFields) {
// Check if the value is an array and if the key exists in allCustomFields
if (
Array.isArray(customFields[key]) &&
appState?.appState.customFields.some((field) => field.key === key)
) {
// Map the values to their corresponding labels
customFields[key] = customFields[key].map((value: string[]) => {
const option: any = (appState?.appState?.customFields as any)
.find((field: any) => field.key === key)
.options.find((opt: any) => opt.key === value)
return option ? ' ' + option.label : ' ' + value
})
}
const data = useMemo(() => {
if (!appState) {
return null
}
const _client = appState.appState.clientList.find(
(el) => el.id === (appState.appState.selectedClient as IClient)?.id,
)
//add comma separator for custom fields
const customFields: any = _client?.customFields

// Iterate through each key in customFields
for (const key in customFields) {
// Check if the value is an array and if the key exists in allCustomFields
if (
Array.isArray(customFields[key]) &&
appState?.appState.customFields.some((field) => field.key === key)
) {
// Map the values to their corresponding labels
customFields[key] = customFields[key].map((value: string[]) => {
const option: any = (appState?.appState?.customFields as any)
.find((field: any) => field.key === key)
.options.find((opt: any) => opt.key === value)
return option ? ' ' + option.label : ' ' + value
})
}
}

let count = 0
appState?.appState.settings?.notifications?.map((el) => {
if (el.show) {
if (appState?.appState.notifications) {
count +=
appState?.appState.notifications[el.key as keyof INotification]
}
let count = 0
appState?.appState.settings?.notifications?.map((el) => {
if (el.show) {
if (appState?.appState.notifications) {
count +=
appState?.appState.notifications[el.key as keyof INotification]
}
})
}
})

const task = { count }
const task = { count }

const invoice = {
count: appState?.appState.notifications?.billing,
}
const invoice = {
count: appState?.appState.notifications?.billing,
}

const form = {
count: appState?.appState.notifications?.forms,
}
const form = {
count: appState?.appState.notifications?.forms,
}

const contract = {
count: appState?.appState.notifications?.contracts,
}
const contract = {
count: appState?.appState.notifications?.contracts,
}

const client = {
..._client,
...customFields,
company: appState?.appState.selectedClientCompanyName,
}
const client = {
..._client,
...customFields,
company: appState?.appState.selectedClientCompanyName,
}

setData({
client,
invoice,
task,
form,
contract,
})
})()
return {
client,
invoice,
task,
form,
contract,
}
}, [
appState?.appState.selectedClient,
appState?.appState.selectedClientCompanyName,
appState?.appState.notifications,
])

console.log('data', data)

return (
<AppDataContext.Provider value={data}>{children}</AppDataContext.Provider>
)
Expand Down

0 comments on commit b965ea1

Please sign in to comment.