feat(admin,admin-ui,medusa): Add Medusa Admin plugin (#3334)
This commit is contained in:
committed by
GitHub
parent
d6b1ad1ccd
commit
40de54b010
69
packages/admin-ui/ui/src/utils/extract-customer-name.ts
Normal file
69
packages/admin-ui/ui/src/utils/extract-customer-name.ts
Normal file
@@ -0,0 +1,69 @@
|
||||
import { Cart, Order } from "@medusajs/medusa"
|
||||
|
||||
/**
|
||||
* Utility for extracting the customer name from a cart or order.
|
||||
*/
|
||||
const extractCustomerName = (obj?: Cart | Order) => {
|
||||
if (!obj) {
|
||||
return "N/A"
|
||||
}
|
||||
|
||||
if (obj.customer) {
|
||||
const firstName = obj.customer.first_name
|
||||
const lastName = obj.customer.last_name
|
||||
|
||||
if (firstName && lastName) {
|
||||
return `${firstName} ${lastName}`
|
||||
}
|
||||
|
||||
if (firstName) {
|
||||
return firstName
|
||||
}
|
||||
|
||||
if (lastName) {
|
||||
return lastName
|
||||
}
|
||||
}
|
||||
|
||||
if (obj.shipping_address) {
|
||||
const firstName = obj.shipping_address.first_name
|
||||
const lastName = obj.shipping_address.last_name
|
||||
|
||||
if (firstName && lastName) {
|
||||
return `${firstName} ${lastName}`
|
||||
}
|
||||
|
||||
if (firstName) {
|
||||
return firstName
|
||||
}
|
||||
|
||||
if (lastName) {
|
||||
return lastName
|
||||
}
|
||||
}
|
||||
|
||||
if (obj.billing_address) {
|
||||
const firstName = obj.billing_address.first_name
|
||||
const lastName = obj.billing_address.last_name
|
||||
|
||||
if (firstName && lastName) {
|
||||
return `${firstName} ${lastName}`
|
||||
}
|
||||
|
||||
if (firstName) {
|
||||
return firstName
|
||||
}
|
||||
|
||||
if (lastName) {
|
||||
return lastName
|
||||
}
|
||||
}
|
||||
|
||||
if (obj.email) {
|
||||
return obj.email
|
||||
}
|
||||
|
||||
return "N/A"
|
||||
}
|
||||
|
||||
export default extractCustomerName
|
||||
Reference in New Issue
Block a user