-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
feat(dashboard): claims first implementation #8468
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
cefbbc2
wip: setup UI
fPolic 4e545b8
Merge branch 'develop' into feat/claims-e2e
fPolic a26b877
wip: rendering modal, adding claim items, create checks
fPolic 76fbdba
Merge branch 'develop' into feat/claims-e2e
fPolic 386a6f0
fix: make form work after merge
fPolic bd68846
fix: continuation of claim edit
fPolic 885653f
Merge branch 'develop' into feat/claims-e2e
riqwan 998d017
Merge branch 'develop' into feat/claims-e2e
riqwan 1473f57
Merge branch 'develop' into feat/claims-e2e
riqwan ac0d8f8
Merge branch 'develop' into feat/claims-e2e
riqwan 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 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
91 changes: 91 additions & 0 deletions
91
packages/admin-next/dashboard/src/routes/orders/order-create-claim/claim-create.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,91 @@ | ||
import { useEffect, useMemo, useState } from "react" | ||
import { useTranslation } from "react-i18next" | ||
import { useNavigate, useParams } from "react-router-dom" | ||
|
||
import { toast } from "@medusajs/ui" | ||
|
||
import { RouteFocusModal } from "../../../components/modals" | ||
import { ClaimCreateForm } from "./components/claim-create-form" | ||
|
||
import { useOrder, useOrderPreview } from "../../../hooks/api/orders" | ||
import { useClaims, useCreateClaim } from "../../../hooks/api/claims" | ||
import { DEFAULT_FIELDS } from "../order-detail/constants" | ||
|
||
let IS_REQUEST_RUNNING = false | ||
|
||
export const ClaimCreate = () => { | ||
const { id } = useParams() | ||
const navigate = useNavigate() | ||
const { t } = useTranslation() | ||
|
||
const { order } = useOrder(id!, { | ||
fields: DEFAULT_FIELDS, | ||
}) | ||
|
||
const { order: preview } = useOrderPreview(id!) | ||
|
||
const [activeClaimId, setActiveClaimId] = useState() | ||
|
||
const { mutateAsync: createClaim } = useCreateClaim(order.id) | ||
|
||
// TODO: GET /claims/:id is not implemented | ||
// const { claim } = useClaim(activeClaimId, undefined, { | ||
// enabled: !!activeClaimId, | ||
// }) | ||
|
||
// TEMP HACK: until the endpoint above is implemented | ||
const { claims } = useClaims(undefined, { | ||
enabled: !!activeClaimId, | ||
limit: 999, | ||
}) | ||
|
||
const claim = useMemo(() => { | ||
if (claims) { | ||
return claims.find((c) => c.id === activeClaimId) | ||
} | ||
}, [claims, activeClaimId]) | ||
|
||
useEffect(() => { | ||
async function run() { | ||
if (IS_REQUEST_RUNNING || !preview) { | ||
return | ||
} | ||
|
||
if (preview.order_change) { | ||
if (preview.order_change.change_type === "claim") { | ||
setActiveClaimId(preview.order_change.claim_id) | ||
} else { | ||
navigate(`/orders/${preview.id}`, { replace: true }) | ||
toast.error(t("orders.claims.activeChangeError")) | ||
} | ||
|
||
return | ||
} | ||
|
||
IS_REQUEST_RUNNING = true | ||
|
||
try { | ||
const { claim } = await createClaim({ | ||
order_id: preview.id, | ||
type: "replace", | ||
}) | ||
setActiveClaimId(claim.id) | ||
} catch (e) { | ||
navigate(`/orders/${preview.id}`, { replace: true }) | ||
toast.error(e.message) | ||
} finally { | ||
IS_REQUEST_RUNNING = false | ||
} | ||
} | ||
|
||
run() | ||
}, [preview]) | ||
|
||
return ( | ||
<RouteFocusModal> | ||
{claim && preview && order && ( | ||
<ClaimCreateForm order={order} claim={claim} preview={preview} /> | ||
)} | ||
</RouteFocusModal> | ||
) | ||
} |
Oops, something went wrong.
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.
todo: This was introduced yesterday. Maybe just replace it in a follow-up PR
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.
Its already replaced here