
* New ConfirmButton component * Update macaw ui * Remove old confim button * New confirm button * Replace all place with new confirm button * Remove ConfirmButtonTransitionState use from mcaw * Does not change button width when showing loader and success state * Test ConfirmButton * Remove story, update tests * WIP change pull_request to push for chromatic * Revert "WIP change pull_request to push for chromatic" This reverts commit 8f0909bf54f185898a7f1d236f072d6544fd5d86. * Add comments * Remove css prop from DialogTable * Make confirm button larger in order send refund
67 lines
1.6 KiB
TypeScript
67 lines
1.6 KiB
TypeScript
import { ConfirmButtonTransitionState } from "@dashboard/components/ConfirmButton";
|
|
import React from "react";
|
|
|
|
interface ManualRefundHookProps {
|
|
submitState: ConfirmButtonTransitionState;
|
|
initialData?: {
|
|
amount?: number;
|
|
description?: string;
|
|
pspReference?: string;
|
|
};
|
|
}
|
|
|
|
export type ManualRefundData = ReturnType<typeof useManualRefund>;
|
|
|
|
export const useManualRefund = ({
|
|
submitState,
|
|
initialData,
|
|
}: ManualRefundHookProps) => {
|
|
const [amount, setAmount] = React.useState<number | undefined>(
|
|
initialData?.amount,
|
|
);
|
|
const [description, setDescription] = React.useState(
|
|
initialData?.description ?? "",
|
|
);
|
|
const [pspReference, setPspReference] = React.useState<string | undefined>(
|
|
initialData?.pspReference,
|
|
);
|
|
|
|
React.useEffect(() => {
|
|
if (submitState === "success") {
|
|
// reset state after submit
|
|
setAmount(undefined);
|
|
setDescription("");
|
|
setPspReference(undefined);
|
|
}
|
|
}, [submitState]);
|
|
|
|
const handleChangeDescription: React.ChangeEventHandler<
|
|
HTMLInputElement
|
|
> = e => {
|
|
setDescription(e.target.value);
|
|
};
|
|
|
|
const handleChangeAmount: React.ChangeEventHandler<HTMLInputElement> = e => {
|
|
const value = parseFloat(e.target.value);
|
|
if (!Number.isNaN(value)) {
|
|
setAmount(value);
|
|
} else {
|
|
setAmount(undefined);
|
|
}
|
|
};
|
|
|
|
const handleChangePspReference: React.ChangeEventHandler<
|
|
HTMLInputElement
|
|
> = e => {
|
|
setPspReference(e.target.value);
|
|
};
|
|
|
|
return {
|
|
amount,
|
|
description,
|
|
pspReference,
|
|
handleChangeDescription,
|
|
handleChangeAmount,
|
|
handleChangePspReference,
|
|
};
|
|
};
|