-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
747f183
commit 5e48a4e
Showing
8 changed files
with
336 additions
and
123 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
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
93 changes: 93 additions & 0 deletions
93
...nPage/subRoutes/CurrentOrgPlan/BillingDetails/EditPaymentMethod/EditPaymentMethodForm.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 |
---|---|---|
@@ -0,0 +1,93 @@ | ||
import { PaymentElement, useElements } from '@stripe/react-stripe-js' | ||
import cs from 'classnames' | ||
import { useState } from 'react' | ||
|
||
import { useUpdatePaymentMethod } from 'services/account/useUpdatePaymentMethod' | ||
import { Theme, useThemeContext } from 'shared/ThemeContext' | ||
import Button from 'ui/Button' | ||
|
||
interface PaymentMethodFormProps { | ||
closeForm: () => void | ||
provider: string | ||
owner: string | ||
} | ||
|
||
const EditPaymentMethodForm = ({ | ||
closeForm, | ||
provider, | ||
owner, | ||
}: PaymentMethodFormProps) => { | ||
const [errorState, setErrorState] = useState('') | ||
Check failure on line 20 in src/pages/PlanPage/subRoutes/CurrentOrgPlan/BillingDetails/EditPaymentMethod/EditPaymentMethodForm.tsx GitHub Actions / Run Lint
|
||
const { theme } = useThemeContext() | ||
const isDarkMode = theme === Theme.DARK | ||
|
||
const elements = useElements() | ||
const { | ||
mutate: updatePaymentMethod, | ||
isLoading, | ||
error, | ||
reset, | ||
} = useUpdatePaymentMethod({ | ||
provider, | ||
owner, | ||
}) | ||
|
||
function submit(e: React.FormEvent) { | ||
e.preventDefault() | ||
|
||
if (!elements) { | ||
return null | ||
} | ||
|
||
updatePaymentMethod(elements.getElement(PaymentElement), { | ||
onSuccess: closeForm, | ||
}) | ||
} | ||
|
||
const showError = (error && !reset) || errorState | ||
|
||
return ( | ||
<form onSubmit={submit} aria-label="form"> | ||
<div className={cs('flex flex-col gap-3')}> | ||
<div className="mt-2 flex flex-col gap-2"> | ||
<PaymentElement | ||
options={{ | ||
layout: 'tabs', | ||
defaultValues: { | ||
billingDetails: { | ||
name: 'John Doe', | ||
}, | ||
}, | ||
}} | ||
/> | ||
<p className="mt-1 text-ds-primary-red"> | ||
{showError && (error?.message || errorState)} | ||
</p> | ||
<div className="mb-8 mt-4 flex gap-1"> | ||
<Button | ||
hook="update-payment" | ||
type="submit" | ||
variant="primary" | ||
disabled={isLoading} | ||
to={undefined} | ||
> | ||
Update | ||
</Button> | ||
<Button | ||
type="button" | ||
hook="cancel-payment" | ||
variant="plain" | ||
disabled={isLoading} | ||
onClick={closeForm} | ||
to={undefined} | ||
> | ||
Cancel | ||
</Button> | ||
</div> | ||
</div> | ||
</div> | ||
</form> | ||
) | ||
} | ||
|
||
export default EditPaymentMethodForm |
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
Oops, something went wrong.