AI store generator for ecommerce, Malaysia first. Laravel 13 + React + TypeScript.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

settings.tsx 8.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. import { Form, Head, Link } from '@inertiajs/react';
  2. import StoreController from '@/actions/App/Http/Controllers/StoreController';
  3. import StoreSettingsController from '@/actions/App/Http/Controllers/StoreSettingsController';
  4. import InputError from '@/components/input-error';
  5. import StoreNav from '@/components/stores/store-nav';
  6. import { Button } from '@/components/ui/button';
  7. import {
  8. Card,
  9. CardContent,
  10. CardDescription,
  11. CardHeader,
  12. CardTitle,
  13. } from '@/components/ui/card';
  14. import { Input } from '@/components/ui/input';
  15. import { Label } from '@/components/ui/label';
  16. import { dashboard } from '@/routes';
  17. import type { StoreSummary } from '@/types';
  18. type Settings = {
  19. whatsapp_number: string | null;
  20. shipping_west: string;
  21. shipping_east: string;
  22. free_shipping_over: string | null;
  23. };
  24. export default function StoreSettings({
  25. store,
  26. settings,
  27. }: {
  28. store: StoreSummary;
  29. settings: Settings;
  30. }) {
  31. return (
  32. <>
  33. <Head title={`Settings - ${store.name}`} />
  34. <div className="mx-auto w-full max-w-6xl space-y-6 p-4">
  35. <div>
  36. <h1 className="text-xl font-semibold">{store.name}</h1>
  37. <p className="text-sm text-muted-foreground">
  38. <Link
  39. href={StoreController.show.url(store.slug)}
  40. className="hover:underline"
  41. >
  42. Back to store
  43. </Link>
  44. </p>
  45. </div>
  46. <StoreNav slug={store.slug} current="settings" />
  47. <Form
  48. {...StoreSettingsController.update.form(store.slug)}
  49. options={{ preserveScroll: true }}
  50. className="max-w-2xl space-y-6"
  51. >
  52. {({ processing, errors }) => (
  53. <>
  54. <Card>
  55. <CardHeader>
  56. <CardTitle>WhatsApp</CardTitle>
  57. <CardDescription>
  58. Shoppers see a WhatsApp chat button on
  59. every page of your store, and on their
  60. order page. Leave empty to hide it.
  61. </CardDescription>
  62. </CardHeader>
  63. <CardContent className="grid gap-2">
  64. <Label htmlFor="whatsapp_number">
  65. WhatsApp number
  66. </Label>
  67. <Input
  68. id="whatsapp_number"
  69. name="whatsapp_number"
  70. type="tel"
  71. inputMode="tel"
  72. maxLength={30}
  73. defaultValue={
  74. settings.whatsapp_number ?? ''
  75. }
  76. placeholder="012-345 6789"
  77. />
  78. <InputError
  79. message={errors.whatsapp_number}
  80. />
  81. </CardContent>
  82. </Card>
  83. <Card>
  84. <CardHeader>
  85. <CardTitle>Shipping fees</CardTitle>
  86. <CardDescription>
  87. Added at checkout, based on the
  88. shopper&rsquo;s state.
  89. </CardDescription>
  90. </CardHeader>
  91. <CardContent className="space-y-5">
  92. <div className="grid gap-5 sm:grid-cols-2">
  93. <div className="grid gap-2">
  94. <Label htmlFor="shipping_west">
  95. Peninsular Malaysia (RM)
  96. </Label>
  97. <Input
  98. id="shipping_west"
  99. name="shipping_west"
  100. inputMode="decimal"
  101. required
  102. defaultValue={
  103. settings.shipping_west
  104. }
  105. />
  106. <InputError
  107. message={errors.shipping_west}
  108. />
  109. </div>
  110. <div className="grid gap-2">
  111. <Label htmlFor="shipping_east">
  112. Sabah, Sarawak and Labuan (RM)
  113. </Label>
  114. <Input
  115. id="shipping_east"
  116. name="shipping_east"
  117. inputMode="decimal"
  118. required
  119. defaultValue={
  120. settings.shipping_east
  121. }
  122. />
  123. <InputError
  124. message={errors.shipping_east}
  125. />
  126. </div>
  127. </div>
  128. <div className="grid gap-2 sm:max-w-[calc(50%-0.625rem)]">
  129. <Label htmlFor="free_shipping_over">
  130. Free shipping on orders over (RM,
  131. optional)
  132. </Label>
  133. <Input
  134. id="free_shipping_over"
  135. name="free_shipping_over"
  136. inputMode="decimal"
  137. defaultValue={
  138. settings.free_shipping_over ??
  139. ''
  140. }
  141. placeholder="100.00"
  142. aria-describedby="free-help"
  143. />
  144. <p
  145. id="free-help"
  146. className="text-xs text-muted-foreground"
  147. >
  148. Leave empty to always charge
  149. shipping. Enter 0 to always ship
  150. free.
  151. </p>
  152. <InputError
  153. message={errors.free_shipping_over}
  154. />
  155. </div>
  156. </CardContent>
  157. </Card>
  158. <Button
  159. disabled={processing}
  160. data-test="save-settings-button"
  161. >
  162. Save settings
  163. </Button>
  164. </>
  165. )}
  166. </Form>
  167. </div>
  168. </>
  169. );
  170. }
  171. StoreSettings.layout = {
  172. breadcrumbs: [
  173. { title: 'Dashboard', href: dashboard() },
  174. { title: 'Settings', href: '#' },
  175. ],
  176. };