-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(wip)migrate manual transaction modal to rhf & new macaw-ui
- Loading branch information
Showing
15 changed files
with
189 additions
and
340 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 8 additions & 14 deletions
22
src/orders/components/OrderManualTransactionForm/components/DescriptionField.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,21 @@ | ||
// @ts-strict-ignore | ||
import { TextField, TextFieldProps } from "@material-ui/core"; | ||
import { Input, InputProps } from "@saleor/macaw-ui-next"; | ||
import React from "react"; | ||
import { Controller } from "react-hook-form"; | ||
|
||
import { useManualTransactionContext } from "../context"; | ||
|
||
export const DescriptionField: React.FC<Omit<TextFieldProps, "onChange" | "value">> = ({ | ||
export const DescriptionField: React.FC<Omit<InputProps, "onChange" | "value">> = ({ | ||
disabled, | ||
...props | ||
}) => { | ||
const { submitState, handleChangeDescription, description } = useManualTransactionContext(); | ||
const { control } = useManualTransactionContext(); | ||
|
||
return ( | ||
<TextField | ||
variant="outlined" | ||
{...props} | ||
disabled={submitState === "loading" || disabled} | ||
onChange={handleChangeDescription} | ||
value={description} | ||
inputProps={{ | ||
...props.inputProps, | ||
maxLength: 512, | ||
"data-test-id": "transactionDescription", | ||
}} | ||
<Controller | ||
name="description" | ||
control={control} | ||
render={({ field }) => <Input {...props} {...field} data-test-id="transactionDescription" />} | ||
/> | ||
); | ||
}; |
18 changes: 11 additions & 7 deletions
18
src/orders/components/OrderManualTransactionForm/components/ErrorText.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,23 @@ | ||
// @ts-strict-ignore | ||
import { Typography, TypographyProps } from "@material-ui/core"; | ||
import { Box, Text, TextProps } from "@saleor/macaw-ui-next"; | ||
import React from "react"; | ||
|
||
import { useManualTransactionContext } from "../context"; | ||
|
||
export const ErrorText: React.FC<TypographyProps> = props => { | ||
const { error } = useManualTransactionContext(); | ||
export const ErrorText: React.FC<Omit<TextProps, "children">> = props => { | ||
const { formState } = useManualTransactionContext(); | ||
|
||
if (!error) { | ||
if (!formState.errors) { | ||
return null; | ||
} | ||
|
||
return ( | ||
<Typography color="error" variant="body2" {...props}> | ||
{error} | ||
</Typography> | ||
<Box display="flex" flexDirection="column" gap={2}> | ||
{Object.values(formState.errors).map((field, key) => ( | ||
<Text color="critical1" key={key} {...props}> | ||
{field.message} | ||
</Text> | ||
))} | ||
</Box> | ||
); | ||
}; |
69 changes: 0 additions & 69 deletions
69
src/orders/components/OrderManualTransactionForm/components/Form.test.tsx
This file was deleted.
Oops, something went wrong.
20 changes: 7 additions & 13 deletions
20
src/orders/components/OrderManualTransactionForm/components/Form.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,17 @@ | ||
// @ts-strict-ignore | ||
import { Box } from "@saleor/macaw-ui-next"; | ||
import React from "react"; | ||
|
||
import { useManualTransactionContext } from "../context"; | ||
|
||
export const Form: React.FC<React.HTMLProps<HTMLFormElement>> = ({ children, ...props }) => { | ||
const { amount, description, pspReference, onAddTransaction } = useManualTransactionContext(); | ||
export const Form: React.FC = ({ children }) => { | ||
const { handleSubmit, onAddTransaction } = useManualTransactionContext(); | ||
|
||
return ( | ||
<form | ||
{...props} | ||
onSubmit={e => { | ||
e.preventDefault(); | ||
|
||
if (amount) { | ||
onAddTransaction({ amount, description, pspReference }); | ||
} | ||
}} | ||
> | ||
{children} | ||
<form onSubmit={handleSubmit(onAddTransaction)}> | ||
<Box display="flex" flexDirection="column" gap={3}> | ||
{children} | ||
</Box> | ||
</form> | ||
); | ||
}; |
36 changes: 24 additions & 12 deletions
36
src/orders/components/OrderManualTransactionForm/components/PriceInputField.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,34 @@ | ||
// @ts-strict-ignore | ||
import PriceField, { PriceFieldProps } from "@dashboard/components/PriceField"; | ||
import { Input, InputProps, Text } from "@saleor/macaw-ui-next"; | ||
import React from "react"; | ||
import { Controller } from "react-hook-form"; | ||
|
||
import { useManualTransactionContext } from "../context"; | ||
|
||
export const PriceInputField: React.FC< | ||
Omit<PriceFieldProps, "currencySymbol" | "onChange" | "value"> | ||
> = ({ disabled, ...props }) => { | ||
const { currency, submitState, handleChangeAmount, amount } = useManualTransactionContext(); | ||
export const PriceInputField: React.FC<Omit<InputProps, "onChange" | "value">> = ({ | ||
disabled, | ||
...props | ||
}) => { | ||
const { | ||
control, | ||
currency, | ||
formState: { errors }, | ||
} = useManualTransactionContext(); | ||
|
||
return ( | ||
<PriceField | ||
{...props} | ||
currencySymbol={currency} | ||
disabled={submitState === "loading" || disabled} | ||
onChange={handleChangeAmount} | ||
value={amount?.toString() ?? ""} | ||
data-test-id="transactAmountInput" | ||
<Controller | ||
control={control} | ||
name="amount" | ||
render={({ field }) => ( | ||
<Input | ||
{...field} | ||
{...props} | ||
type="number" | ||
data-test-id="transactAmountInput" | ||
endAdornment={<Text size={2}>{currency}</Text>} | ||
error={!!errors.amount} | ||
/> | ||
)} | ||
/> | ||
); | ||
}; |
Oops, something went wrong.