-
Notifications
You must be signed in to change notification settings - Fork 35
(feat): Commands to cancel a spend request #77
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
6baed9c
commands to cancel a spend request
kreese-stripe 63f6716
Merge branch 'main' into kreese/cancel-action
kreese-stripe 3a7342f
document
kreese-stripe 43cac6b
nit: remove unneeded status text
kreese-stripe 93661a0
code improvements
kreese-stripe 76b54a9
Fix typecheck
kreese-stripe 7816760
Just go back to old promise approach
kreese-stripe File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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,70 @@ | ||
| import type { ISpendRequestResource, SpendRequest } from '@stripe/link-sdk'; | ||
| import { Box, Text } from 'ink'; | ||
| import Spinner from 'ink-spinner'; | ||
| import type React from 'react'; | ||
| import { useEffect, useState } from 'react'; | ||
|
|
||
| interface CancelSpendRequestProps { | ||
| repository: ISpendRequestResource; | ||
| id: string; | ||
| onComplete: (result: SpendRequest | null) => void; | ||
| } | ||
|
|
||
| export const CancelSpendRequest: React.FC<CancelSpendRequestProps> = ({ | ||
| repository, | ||
| id, | ||
| onComplete, | ||
| }) => { | ||
| const [status, setStatus] = useState<'loading' | 'success' | 'error'>( | ||
| 'loading', | ||
| ); | ||
| const [request, setRequest] = useState<SpendRequest | null>(null); | ||
| const [error, setError] = useState<string>(''); | ||
|
|
||
| useEffect(() => { | ||
| const run = async () => { | ||
| try { | ||
| const result = await repository.cancelSpendRequest(id); | ||
| setRequest(result); | ||
| setStatus('success'); | ||
| setTimeout(() => onComplete(result), 1500); | ||
| } catch (err) { | ||
| setError((err as Error).message); | ||
| setStatus('error'); | ||
| setTimeout(() => onComplete(null), 1500); | ||
| } | ||
| }; | ||
|
|
||
| run(); | ||
| }, [repository, id, onComplete]); | ||
|
|
||
| if (status === 'loading') { | ||
| return ( | ||
| <Box> | ||
| <Text color="cyan"> | ||
| <Spinner type="dots" /> Canceling spend request {id}... | ||
| </Text> | ||
| </Box> | ||
| ); | ||
| } | ||
|
|
||
| if (status === 'error') { | ||
| return ( | ||
| <Box flexDirection="column"> | ||
| <Text color="red">✗ Failed to cancel spend request</Text> | ||
| <Text color="red">{error}</Text> | ||
| </Box> | ||
| ); | ||
| } | ||
|
|
||
| return ( | ||
| <Box flexDirection="column"> | ||
| <Text color="green">✓ Spend request canceled</Text> | ||
| <Box flexDirection="column" marginTop={1} paddingX={2}> | ||
| <Text> | ||
| ID: <Text bold>{request?.id}</Text> | ||
| </Text> | ||
| </Box> | ||
| </Box> | ||
| ); | ||
| }; |
This file contains hidden or 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 hidden or 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,22 @@ | ||
| import { storage } from '@stripe/link-sdk'; | ||
|
|
||
| interface AuthErrorOptions { | ||
| code: string; | ||
| message: string; | ||
| cta?: { commands: { command: string; description: string }[] }; | ||
| } | ||
|
|
||
| const NOT_AUTHENTICATED_ERROR: AuthErrorOptions = { | ||
| code: 'NOT_AUTHENTICATED', | ||
| message: 'Not authenticated. Run "link-cli auth login" first.', | ||
| cta: { | ||
| commands: [{ command: 'auth login', description: 'Log in to Link' }], | ||
| }, | ||
| }; | ||
|
|
||
| export function requireAuth(c: { error: (err: AuthErrorOptions) => never }) { | ||
| if (!storage.isAuthenticated()) { | ||
| return c.error(NOT_AUTHENTICATED_ERROR); | ||
| } | ||
| return null; | ||
| } |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lets make sure we add this into the various readme, skill, helper text etc