Browse Source

chore(gui-v2): move feedback form to useGlobal

pull/2877/head
braks 2 years ago
parent
commit
f9dd082d51
  1. 14
      packages/nc-gui-v2/composables/useGlobal/state.ts
  2. 8
      packages/nc-gui-v2/composables/useGlobal/types.ts
  3. 5
      packages/nc-gui-v2/composables/useGlobalState/initialFeedBackForm.ts
  4. 7
      packages/nc-gui-v2/lib/types.ts

14
packages/nc-gui-v2/composables/useGlobal/state.ts

@ -24,7 +24,7 @@ export function useGlobalState(storageKey = 'nocodb-gui-v2'): State {
* If the user has not set a preferred language, we fallback to 'en'. * If the user has not set a preferred language, we fallback to 'en'.
* If the user has set a preferred language, we try to find a matching locale in the available locales. * If the user has set a preferred language, we try to find a matching locale in the available locales.
*/ */
const preferredLanguage = preferredLanguages.reduce<string>((locale, language) => { const preferredLanguage = preferredLanguages.reduce((locale, language) => {
/** split language to language and code, e.g. en-GB -> [en, GB] */ /** split language to language and code, e.g. en-GB -> [en, GB] */
const [lang, code] = language.split(/[_-]/) const [lang, code] = language.split(/[_-]/)
@ -46,7 +46,17 @@ export function useGlobalState(storageKey = 'nocodb-gui-v2'): State {
}, 'en' /** fallback locale */) }, 'en' /** fallback locale */)
/** State */ /** State */
const initialState: StoredState = { token: null, user: null, lang: preferredLanguage, darkMode: prefersDarkMode } const initialState: StoredState = {
token: null,
user: null,
lang: preferredLanguage,
darkMode: prefersDarkMode,
feedbackForm: {
url: 'https://docs.google.com/forms/d/e/1FAIpQLSeTlAfZjszgr53lArz3NvUEnJGOT9JtG9NAU5d0oQwunDS2Pw/viewform?embedded=true',
createdAt: new Date('2020-01-01T00:00:00.000Z').toISOString(),
isHidden: false,
},
}
/** saves a reactive state, any change to these values will write/delete to localStorage */ /** saves a reactive state, any change to these values will write/delete to localStorage */
const storage = useStorage<StoredState>(storageKey, initialState) const storage = useStorage<StoredState>(storageKey, initialState)

8
packages/nc-gui-v2/composables/useGlobal/types.ts

@ -4,11 +4,19 @@ import type { JwtPayload } from 'jwt-decode'
import type { User } from '~/lib' import type { User } from '~/lib'
import type { useCounter } from '#imports' import type { useCounter } from '#imports'
export interface FeedbackForm {
url: string
createdAt: string
isHidden: boolean
lastFormPollDate?: string
}
export interface StoredState { export interface StoredState {
token: string | null token: string | null
user: User | null user: User | null
lang: string lang: string
darkMode: boolean darkMode: boolean
feedbackForm: FeedbackForm
} }
export type State = ToRefs<Omit<StoredState, 'token'>> & { export type State = ToRefs<Omit<StoredState, 'token'>> & {

5
packages/nc-gui-v2/composables/useGlobalState/initialFeedBackForm.ts

@ -1,5 +0,0 @@
export default {
url: 'https://docs.google.com/forms/d/e/1FAIpQLSeTlAfZjszgr53lArz3NvUEnJGOT9JtG9NAU5d0oQwunDS2Pw/viewform?embedded=true',
createdAt: new Date('2020-01-01T00:00:00.000Z').toISOString(),
isHidden: false,
}

7
packages/nc-gui-v2/lib/types.ts

@ -8,11 +8,4 @@ export interface User {
roles: Roles roles: Roles
} }
export interface FeedbackForm {
url: string
createdAt: string
isHidden: boolean
lastFormPollDate?: string
}
export type Roles = Record<Role, boolean> export type Roles = Record<Role, boolean>

Loading…
Cancel
Save