sanity-plugin-dashboard-widget-vercel 3.1.0 → 3.1.2

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,10 +1,8 @@
1
- // @ts-expect-error - fix typings later
2
1
  import {yupResolver} from '@hookform/resolvers/yup'
3
2
  import {Box, Button, Dialog, Flex, Stack} from '@sanity/ui'
4
3
  import {uuid} from '@sanity/uuid'
5
4
  import {useMachine} from '@xstate/react'
6
5
  import React, {FC} from 'react'
7
- // @ts-expect-error - fix typings later
8
6
  import {useForm} from 'react-hook-form'
9
7
  import * as yup from 'yup'
10
8
 
@@ -105,20 +103,20 @@ const DialogForm: FC<Props> = (props: Props) => {
105
103
  const formUpdating =
106
104
  formState.matches('creating') || formState.matches('deleting') || formState.matches('updating')
107
105
 
108
- // react-hook-form
106
+ // react-hook-form v7
109
107
  const {
110
- // Read the formState before render to subscribe the form state through Proxy
111
108
  formState: {errors, isDirty, isValid},
112
109
  handleSubmit,
113
110
  register,
114
- } = useForm({
111
+ } = useForm<FormData>({
112
+ // @ts-expect-error - fix typings later
115
113
  defaultValues: {
116
114
  deployHook: deploymentTarget?.deployHook || '',
117
115
  deployLimit: deploymentTarget?.deployLimit || 5,
118
- name: deploymentTarget?.name,
119
- projectId: deploymentTarget?.projectId,
116
+ name: deploymentTarget?.name || '',
117
+ projectId: deploymentTarget?.projectId || '',
120
118
  teamId: deploymentTarget?.teamId || '',
121
- token: deploymentTarget?.token,
119
+ token: deploymentTarget?.token || '',
122
120
  },
123
121
  mode: 'onChange',
124
122
  resolver: yupResolver(formSchema),
@@ -186,24 +184,24 @@ const DialogForm: FC<Props> = (props: Props) => {
186
184
  description="Name displayed in this plugin (e.g. production, staging)"
187
185
  error={errors?.name}
188
186
  label="Name"
189
- name="name"
190
- ref={register}
187
+ // @ts-expect-error - fix typings later
188
+ {...register('name')}
191
189
  />
192
190
 
193
191
  <FormFieldInputText
194
192
  disabled={formUpdating}
195
193
  error={errors?.token}
196
194
  label="Vercel Account Token"
197
- name="token"
198
- ref={register}
195
+ // @ts-expect-error - fix typings later
196
+ {...register('token')}
199
197
  />
200
198
 
201
199
  <FormFieldInputText
202
200
  disabled={formUpdating}
203
201
  error={errors?.projectId}
204
202
  label="Vercel Project ID"
205
- name="projectId"
206
- ref={register}
203
+ // @ts-expect-error - fix typings later
204
+ {...register('projectId')}
207
205
  />
208
206
 
209
207
  <FormFieldInputText
@@ -211,8 +209,8 @@ const DialogForm: FC<Props> = (props: Props) => {
211
209
  disabled={formUpdating}
212
210
  error={errors?.teamId}
213
211
  label="Vercel Team ID (optional)"
214
- name="teamId"
215
- ref={register}
212
+ // @ts-expect-error - fix typings later
213
+ {...register('teamId')}
216
214
  />
217
215
 
218
216
  <FormFieldInputText
@@ -220,16 +218,16 @@ const DialogForm: FC<Props> = (props: Props) => {
220
218
  disabled={formUpdating}
221
219
  error={errors?.deployHook}
222
220
  label="Vercel Deploy Hook (optional)"
223
- name="deployHook"
224
- ref={register}
221
+ // @ts-expect-error - fix typings later
222
+ {...register('deployHook')}
225
223
  />
226
224
 
227
225
  <FormFieldInputText
228
226
  disabled={formUpdating}
229
227
  error={errors?.deployLimit}
230
228
  label="Number of deploys to display"
231
- name="deployLimit"
232
- ref={register({valueAsNumber: true})}
229
+ // @ts-expect-error - fix typings later
230
+ {...register('deployLimit', {valueAsNumber: true})}
233
231
  />
234
232
  </Stack>
235
233
  </Box>
@@ -1,7 +1,6 @@
1
1
  import {ErrorOutlineIcon} from '@sanity/icons'
2
2
  import {Box, Inline, Text, Tooltip} from '@sanity/ui'
3
3
  import React, {FC} from 'react'
4
- // @ts-expect-error - fix typings later
5
4
  import {FieldError} from 'react-hook-form'
6
5
  import {styled} from 'styled-components'
7
6
 
@@ -1,6 +1,5 @@
1
1
  import {Box, TextInput} from '@sanity/ui'
2
2
  import React, {forwardRef} from 'react'
3
- // @ts-expect-error - fix typings later
4
3
  import {FieldError} from 'react-hook-form'
5
4
 
6
5
  import FormFieldInputLabel from '../FormFieldInputLabel'
@@ -13,12 +12,12 @@ type Props = {
13
12
  name: string
14
13
  placeholder?: string
15
14
  value?: string
15
+ onChange?: React.ChangeEventHandler<HTMLInputElement>
16
+ onBlur?: React.FocusEventHandler<HTMLInputElement>
16
17
  }
17
18
 
18
- type Ref = HTMLInputElement
19
-
20
- const FormFieldInputText = forwardRef<Ref, Props>((props: Props, ref) => {
21
- const {description, disabled, error, label, name, placeholder, value} = props
19
+ const FormFieldInputText = forwardRef<HTMLInputElement, Props>((props: Props, ref) => {
20
+ const {description, disabled, error, label, name, placeholder, value, onChange, onBlur} = props
22
21
 
23
22
  return (
24
23
  <Box>
@@ -33,6 +32,8 @@ const FormFieldInputText = forwardRef<Ref, Props>((props: Props, ref) => {
33
32
  id={name}
34
33
  name={name}
35
34
  placeholder={placeholder}
35
+ onChange={onChange}
36
+ onBlur={onBlur}
36
37
  ref={ref}
37
38
  />
38
39
  </Box>
@@ -1,5 +1,5 @@
1
1
  import hash from 'object-hash'
2
- import {useQuery} from 'react-query'
2
+ import {useQuery} from '@tanstack/react-query'
3
3
 
4
4
  import fetcher from '../utils/fetcher'
5
5
  import {API_ENDPOINT_ALIASES, API_ENDPOINT_DEPLOYMENTS} from '../constants'
@@ -22,19 +22,17 @@ const useDeployments = (deploymentTarget: Sanity.DeploymentTarget, options?: Opt
22
22
  isSuccess: deploymentsIsSuccess,
23
23
  error: deploymentsError,
24
24
  refetch,
25
- } = useQuery<{deployments: Vercel.Deployment[]}, Error>(
26
- hash(deploymentTarget), // key
27
- () => fetchUrl(API_ENDPOINT_DEPLOYMENTS, deployParams),
28
- {
29
- enabled: options?.enabled ?? true,
30
- refetchInterval: 20000, // ms
31
- refetchIntervalInBackground: false,
32
- refetchOnMount: true,
33
- refetchOnReconnect: 'always',
34
- refetchOnWindowFocus: false,
35
- retry: false,
36
- }
37
- )
25
+ } = useQuery<{deployments: Vercel.Deployment[]}, Error>({
26
+ queryKey: [hash(deploymentTarget)],
27
+ queryFn: () => fetchUrl(API_ENDPOINT_DEPLOYMENTS, deployParams),
28
+ enabled: options?.enabled ?? true,
29
+ refetchInterval: 20000, // ms
30
+ refetchIntervalInBackground: false,
31
+ refetchOnMount: true,
32
+ refetchOnReconnect: 'always',
33
+ refetchOnWindowFocus: false,
34
+ retry: false,
35
+ })
38
36
 
39
37
  // Fetch aliases (only if deployments have been retrieved)
40
38
  const aliasParams = new URLSearchParams()
@@ -55,17 +53,15 @@ const useDeployments = (deploymentTarget: Sanity.DeploymentTarget, options?: Opt
55
53
  }
56
54
  },
57
55
  Error
58
- >(
59
- `${hash(deploymentTarget)}-aliases`, // key
60
- () => fetchUrl(API_ENDPOINT_ALIASES, aliasParams),
61
- {
62
- enabled: !!deploymentsData,
63
- refetchOnMount: false,
64
- refetchOnReconnect: false,
65
- refetchOnWindowFocus: false,
66
- retry: false,
67
- }
68
- )
56
+ >({
57
+ queryKey: [hash(deploymentTarget), 'aliases'],
58
+ queryFn: () => fetchUrl(API_ENDPOINT_ALIASES, aliasParams),
59
+ enabled: !!deploymentsData,
60
+ refetchOnMount: false,
61
+ refetchOnReconnect: false,
62
+ refetchOnWindowFocus: false,
63
+ retry: false,
64
+ })
69
65
 
70
66
  const aliases = aliasesData?.aliases as Vercel.Alias[]
71
67