AI store generator for ecommerce, Malaysia first. Laravel 13 + React + TypeScript.
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

publish-panel.tsx 6.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. import { Form } from '@inertiajs/react';
  2. import { ExternalLink, Globe, GlobeLock } from 'lucide-react';
  3. import StorePublishController from '@/actions/App/Http/Controllers/StorePublishController';
  4. import { Button } from '@/components/ui/button';
  5. import {
  6. Dialog,
  7. DialogClose,
  8. DialogContent,
  9. DialogDescription,
  10. DialogFooter,
  11. DialogHeader,
  12. DialogTitle,
  13. DialogTrigger,
  14. } from '@/components/ui/dialog';
  15. import { formatDateTime } from '@/lib/money';
  16. import type { Store } from '@/types';
  17. /**
  18. * Shows whether the store is live, where shoppers open it, and the buttons to publish or take it offline.
  19. */
  20. export default function PublishPanel({
  21. store,
  22. busy,
  23. }: {
  24. store: Store;
  25. busy: boolean;
  26. }) {
  27. const address = store.live_url.replace(/^https?:\/\//, '');
  28. if (!store.is_published) {
  29. return (
  30. <div className="flex flex-wrap items-center justify-between gap-4 rounded-xl border p-4">
  31. <div className="flex items-start gap-3">
  32. <GlobeLock className="mt-0.5 size-5 shrink-0 text-muted-foreground" />
  33. <div>
  34. <p className="font-medium">Your store is not live</p>
  35. <p className="mt-0.5 text-sm text-muted-foreground">
  36. Only you can see it. When you publish, shoppers can
  37. open it at{' '}
  38. <span className="font-medium text-foreground">
  39. {address}
  40. </span>
  41. .
  42. </p>
  43. </div>
  44. </div>
  45. <Form {...StorePublishController.publish.form(store.slug)}>
  46. {({ processing }) => (
  47. <Button
  48. disabled={processing || busy}
  49. data-test="publish-store-button"
  50. >
  51. <Globe />
  52. Publish store
  53. </Button>
  54. )}
  55. </Form>
  56. </div>
  57. );
  58. }
  59. return (
  60. <div
  61. className="space-y-3 rounded-xl border p-4"
  62. data-test="publish-panel-live"
  63. >
  64. <div className="flex flex-wrap items-center justify-between gap-4">
  65. <div className="flex items-start gap-3">
  66. <Globe className="mt-0.5 size-5 shrink-0 text-green-600 dark:text-green-400" />
  67. <div className="min-w-0">
  68. <p className="font-medium">Your store is live</p>
  69. <p className="mt-0.5 text-sm break-all">
  70. <a
  71. href={store.live_url}
  72. target="_blank"
  73. rel="noreferrer"
  74. className="inline-flex items-center gap-1 underline underline-offset-2"
  75. >
  76. {address}
  77. <ExternalLink className="size-3.5" />
  78. </a>
  79. </p>
  80. <p className="mt-0.5 text-xs text-muted-foreground">
  81. Last published {formatDateTime(store.published_at)}
  82. </p>
  83. </div>
  84. </div>
  85. <Dialog>
  86. <DialogTrigger asChild>
  87. <Button
  88. variant="outline"
  89. size="sm"
  90. data-test="unpublish-store-button"
  91. >
  92. Take offline
  93. </Button>
  94. </DialogTrigger>
  95. <DialogContent>
  96. <DialogHeader>
  97. <DialogTitle>Take your store offline?</DialogTitle>
  98. <DialogDescription>
  99. Shoppers will no longer be able to open{' '}
  100. {address}. Your design, products and orders are
  101. kept, and you can publish again any time.
  102. </DialogDescription>
  103. </DialogHeader>
  104. <DialogFooter>
  105. <DialogClose asChild>
  106. <Button variant="outline">Cancel</Button>
  107. </DialogClose>
  108. <Form
  109. {...StorePublishController.unpublish.form(
  110. store.slug,
  111. )}
  112. >
  113. {({ processing }) => (
  114. <Button
  115. variant="destructive"
  116. disabled={processing}
  117. data-test="confirm-unpublish-button"
  118. >
  119. Take offline
  120. </Button>
  121. )}
  122. </Form>
  123. </DialogFooter>
  124. </DialogContent>
  125. </Dialog>
  126. </div>
  127. {store.has_unpublished_changes && (
  128. <div className="flex flex-wrap items-center justify-between gap-3 rounded-lg bg-amber-50 p-3 text-sm text-amber-900 dark:bg-amber-950/40 dark:text-amber-200">
  129. <p>
  130. You changed the design since you last published.
  131. Shoppers still see the older version.
  132. </p>
  133. <Form {...StorePublishController.publish.form(store.slug)}>
  134. {({ processing }) => (
  135. <Button
  136. size="sm"
  137. disabled={processing || busy}
  138. data-test="publish-changes-button"
  139. >
  140. Publish changes
  141. </Button>
  142. )}
  143. </Form>
  144. </div>
  145. )}
  146. </div>
  147. );
  148. }