Use RHF bindings in Search app (#500)

* Use RHF Macaw bindings from shared package

* Update the nextjs config
This commit is contained in:
Krzysztof Wolski 2023-05-22 18:14:05 +02:00 committed by GitHub
parent 8a339fc31b
commit 590150b8c4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 31 additions and 49 deletions

View file

@ -0,0 +1,5 @@
---
"saleor-app-search": patch
---
Use input component from the shared package.

View file

@ -23,7 +23,7 @@ const moduleExports = {
},
],
},
transpilePackages: ["@saleor/apps-shared", "@saleor/apps-ui"],
transpilePackages: ["@saleor/apps-shared", "@saleor/apps-ui", "@saleor/react-hook-form-macaw"],
sentry: {
/*
* Use `hidden-source-map` rather than `source-map` as the Webpack `devtool`

View file

@ -20,6 +20,7 @@
"@saleor/app-sdk": "0.38.0",
"@saleor/apps-shared": "workspace:*",
"@saleor/apps-ui": "workspace:*",
"@saleor/react-hook-form-macaw": "workspace:*",
"@saleor/macaw-ui": "^0.8.0-pre.84",
"@sentry/nextjs": "^7.46.0",
"@types/debug": "^4.1.7",

View file

@ -1,9 +1,10 @@
import { useAuthenticatedFetch } from "@saleor/app-sdk/app-bridge";
import { Controller, useForm } from "react-hook-form";
import { useForm } from "react-hook-form";
import { useMutation, useQuery, useQueryClient } from "react-query";
import { fetchConfiguration } from "../lib/configuration";
import { Box, Button, Divider, Input, Text } from "@saleor/macaw-ui/next";
import { Box, Button, Divider, Text } from "@saleor/macaw-ui/next";
import { Input } from "@saleor/react-hook-form-macaw";
import { useDashboardNotification } from "@saleor/apps-shared";
import { AlgoliaSearchProvider } from "../lib/algolia/algoliaSearchProvider";
import { zodResolver } from "@hookform/resolvers/zod";
@ -93,61 +94,33 @@ export const AlgoliaConfigurationForm = () => {
<form onSubmit={onFormSubmit}>
<Box padding={8}>
<Box marginBottom={8}>
<Controller
name="appId"
<Input
control={control}
render={({ field, fieldState }) => {
return (
<Input
disabled={isFormDisabled}
required
label="Application ID"
error={fieldState.invalid}
helperText={
fieldState.error?.message ?? "Usually 10 characters, e.g. XYZAAABB00"
}
{...field}
/>
);
}}
name="appId"
disabled={isFormDisabled}
required
label="Application ID"
helperText="Usually 10 characters, e.g. XYZAAABB00"
/>
</Box>
<Box marginBottom={8} key={"secret"} /* todo why is this "key" here? */>
<Controller
name="secretKey"
<Input
control={control}
render={({ field, fieldState }) => (
<Input
helperText={
fieldState.error?.message ?? "In Algolia dashboard it's a masked field"
}
disabled={isFormDisabled}
required
label="Admin API Key"
error={fieldState.invalid}
{...field}
/>
)}
name="secretKey"
disabled={isFormDisabled}
required
label="Admin API Key"
helperText="In Algolia dashboard it's a masked field"
/>
</Box>
<Controller
name="indexNamePrefix"
<Input
control={control}
render={({ field, fieldState }) => {
return (
<Input
disabled={isFormDisabled}
error={fieldState.invalid}
label="Index name prefix"
helperText={
fieldState.error?.message ??
'Optional prefix, you can add "test" or "staging" to test the app'
}
{...field}
/>
);
}}
name="indexNamePrefix"
disabled={isFormDisabled}
required
label="Index name prefix"
helperText='Optional prefix, you can add "test" or "staging" to test the app'
/>
{credentialsValidationError && (

View file

@ -1251,6 +1251,9 @@ importers:
'@saleor/macaw-ui':
specifier: ^0.8.0-pre.84
version: 0.8.0-pre.84(@types/react@18.0.38)(react-dom@18.2.0)(react@18.2.0)
'@saleor/react-hook-form-macaw':
specifier: workspace:*
version: link:../../packages/react-hook-form-macaw
'@sentry/nextjs':
specifier: ^7.46.0
version: 7.46.0(next@13.3.0)(react@18.2.0)