@sanity/assist 1.2.15-lang.2 → 1.2.15-lang.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,9 +1,10 @@
1
- import {useClient, useCurrentUser, useSchema} from 'sanity'
1
+ import {Path, pathToString, useClient, useCurrentUser, useSchema} from 'sanity'
2
2
  import {useCallback, useMemo, useState} from 'react'
3
3
  import {serializeSchema} from './schemas/serialize/serializeSchema'
4
4
  import {useToast} from '@sanity/ui'
5
5
  import {SanityClient} from '@sanity/client'
6
- import {TranslationMap} from './translate/paths'
6
+ import {FieldLanguageMap} from './translate/paths'
7
+ import {documentRootKey} from './types'
7
8
 
8
9
  export interface UserTextInstance {
9
10
  blockKey: string
@@ -26,6 +27,13 @@ export interface InstructStatus {
26
27
  validToken: boolean
27
28
  }
28
29
 
30
+ export interface TranslateRequest {
31
+ documentId: string
32
+ translatePath: Path
33
+ languagePath?: string
34
+ fieldLanguageMap?: FieldLanguageMap[]
35
+ }
36
+
29
37
  const basePath = '/assist/tasks/instruction'
30
38
 
31
39
  export function useApiClient(customApiClient?: (defaultClient: SanityClient) => SanityClient) {
@@ -44,15 +52,7 @@ export function useTranslate(apiClient: SanityClient) {
44
52
  const toast = useToast()
45
53
 
46
54
  const translate = useCallback(
47
- ({
48
- documentId,
49
- languagePath,
50
- fieldLanguageMap,
51
- }: {
52
- documentId: string
53
- languagePath?: string
54
- fieldLanguageMap?: TranslationMap[]
55
- }) => {
55
+ ({documentId, languagePath, translatePath, fieldLanguageMap}: TranslateRequest) => {
56
56
  setLoading(true)
57
57
 
58
58
  return apiClient
@@ -66,6 +66,8 @@ export function useTranslate(apiClient: SanityClient) {
66
66
  types,
67
67
  languagePath,
68
68
  fieldLanguageMap,
69
+ translatePath:
70
+ translatePath.length === 0 ? documentRootKey : pathToString(translatePath),
69
71
  userId: user?.id,
70
72
  },
71
73
  })