-
-
Notifications
You must be signed in to change notification settings - Fork 4
Release v1.0.4 #368
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
Release v1.0.4 #368
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
2c77e2a
(SP: 3) [Backend] add Nova Poshta shipping foundation + checkout pers…
liudmylasovetovs 4dd23b2
(SP: 2) [Frontend] Reduce Vercel variable costs via caching and analy…
ViktorSvertoka cf43f36
fix(build): align Netlify Node version and remove SpeedInsights import
ViktorSvertoka e07941e
chore(release): bump version to 1.0.4
ViktorSvertoka 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
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
137 changes: 137 additions & 0 deletions
137
frontend/app/[locale]/admin/shop/orders/[id]/ShippingActions.tsx
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,137 @@ | ||
| 'use client'; | ||
|
|
||
| import { useRouter } from 'next/navigation'; | ||
| import { useId, useState, useTransition } from 'react'; | ||
|
|
||
| type ActionName = 'retry_label_creation' | 'mark_shipped' | 'mark_delivered'; | ||
|
|
||
| type Props = { | ||
| orderId: string; | ||
| csrfToken: string; | ||
| shippingStatus: string | null; | ||
| shipmentStatus: string | null; | ||
| }; | ||
|
|
||
| function actionEnabled(args: { | ||
| action: ActionName; | ||
| shippingStatus: string | null; | ||
| shipmentStatus: string | null; | ||
| }): boolean { | ||
| if (args.action === 'retry_label_creation') { | ||
| return ( | ||
| args.shipmentStatus === 'failed' || args.shipmentStatus === 'needs_attention' | ||
| ); | ||
| } | ||
| if (args.action === 'mark_shipped') { | ||
| return args.shippingStatus === 'label_created'; | ||
| } | ||
| return args.shippingStatus === 'shipped'; | ||
| } | ||
|
|
||
| export function ShippingActions({ | ||
| orderId, | ||
| csrfToken, | ||
| shippingStatus, | ||
| shipmentStatus, | ||
| }: Props) { | ||
| const router = useRouter(); | ||
| const [isPending, startTransition] = useTransition(); | ||
| const [error, setError] = useState<string | null>(null); | ||
| const errorId = useId(); | ||
|
|
||
| async function runAction(action: ActionName) { | ||
| setError(null); | ||
|
|
||
| let res: Response; | ||
| try { | ||
| res = await fetch(`/api/shop/admin/orders/${orderId}/shipping`, { | ||
| method: 'POST', | ||
| credentials: 'same-origin', | ||
| headers: { | ||
| 'Content-Type': 'application/json', | ||
| 'x-csrf-token': csrfToken, | ||
| }, | ||
| body: JSON.stringify({ action }), | ||
| }); | ||
| } catch (err) { | ||
| const msg = | ||
| err instanceof Error && err.message ? err.message : 'NETWORK_ERROR'; | ||
| setError(msg); | ||
| return; | ||
| } | ||
|
|
||
| let json: any = null; | ||
| try { | ||
| json = await res.json(); | ||
| } catch { | ||
| // ignore | ||
| } | ||
|
|
||
| if (!res.ok) { | ||
| setError(json?.code ?? json?.message ?? `HTTP_${res.status}`); | ||
| return; | ||
| } | ||
|
|
||
| startTransition(() => { | ||
| router.refresh(); | ||
| }); | ||
| } | ||
|
|
||
| const retryEnabled = actionEnabled({ | ||
| action: 'retry_label_creation', | ||
| shippingStatus, | ||
| shipmentStatus, | ||
| }); | ||
| const shippedEnabled = actionEnabled({ | ||
| action: 'mark_shipped', | ||
| shippingStatus, | ||
| shipmentStatus, | ||
| }); | ||
| const deliveredEnabled = actionEnabled({ | ||
| action: 'mark_delivered', | ||
| shippingStatus, | ||
| shipmentStatus, | ||
| }); | ||
|
|
||
| return ( | ||
| <div className="space-y-3"> | ||
| <div className="flex flex-wrap gap-2"> | ||
| <button | ||
| type="button" | ||
| onClick={() => runAction('retry_label_creation')} | ||
| disabled={isPending || !retryEnabled} | ||
| aria-busy={isPending} | ||
| className="border-border text-foreground hover:bg-secondary rounded-md border px-3 py-1.5 text-sm font-medium transition-colors disabled:cursor-not-allowed disabled:opacity-50" | ||
| > | ||
| Retry label creation | ||
| </button> | ||
|
|
||
| <button | ||
| type="button" | ||
| onClick={() => runAction('mark_shipped')} | ||
| disabled={isPending || !shippedEnabled} | ||
| aria-busy={isPending} | ||
| className="border-border text-foreground hover:bg-secondary rounded-md border px-3 py-1.5 text-sm font-medium transition-colors disabled:cursor-not-allowed disabled:opacity-50" | ||
| > | ||
| Mark shipped | ||
| </button> | ||
|
|
||
| <button | ||
| type="button" | ||
| onClick={() => runAction('mark_delivered')} | ||
| disabled={isPending || !deliveredEnabled} | ||
| aria-busy={isPending} | ||
| className="border-border text-foreground hover:bg-secondary rounded-md border px-3 py-1.5 text-sm font-medium transition-colors disabled:cursor-not-allowed disabled:opacity-50" | ||
| > | ||
| Mark delivered | ||
| </button> | ||
| </div> | ||
|
|
||
| {error ? ( | ||
| <p id={errorId} role="alert" className="text-destructive text-xs"> | ||
| {error} | ||
| </p> | ||
| ) : null} | ||
| </div> | ||
| ); | ||
| } |
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.
Shipping toggle examples/comments conflict with runtime parsing.
This file suggests enabling shipping with
=1, butfrontend/lib/env/nova-poshta.tschecks for literal'true'. Using1will keep features disabled unexpectedly.💡 Suggested patch
🤖 Prompt for AI Agents