AI store generator for ecommerce, Malaysia first. Laravel 13 + React + TypeScript.
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

create.tsx 7.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. import { Form, Head, Link } from '@inertiajs/react';
  2. import StoreController from '@/actions/App/Http/Controllers/StoreController';
  3. import Heading from '@/components/heading';
  4. import InputError from '@/components/input-error';
  5. import { Button } from '@/components/ui/button';
  6. import { Input } from '@/components/ui/input';
  7. import { Label } from '@/components/ui/label';
  8. import { dashboard } from '@/routes';
  9. import { create } from '@/routes/stores';
  10. import type { SelectOption } from '@/types';
  11. const fieldClass =
  12. 'w-full min-w-0 rounded-md border border-input bg-transparent px-3 py-2 text-base shadow-xs transition-[color,box-shadow] outline-none placeholder:text-muted-foreground focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50 disabled:cursor-not-allowed disabled:opacity-50 md:text-sm';
  13. /**
  14. * The store name typed on our home page, if any: from the address (?name=...) or, after signing up,
  15. * kept in this browser. Empty otherwise.
  16. */
  17. function pendingName(): string {
  18. if (typeof window === 'undefined') {
  19. return '';
  20. }
  21. const fromAddress = new URLSearchParams(window.location.search).get('name');
  22. if (fromAddress) {
  23. return fromAddress.slice(0, 60);
  24. }
  25. try {
  26. return (window.localStorage.getItem('pending-store-name') ?? '').slice(
  27. 0,
  28. 60,
  29. );
  30. } catch {
  31. return '';
  32. }
  33. }
  34. function forgetPendingName(): void {
  35. try {
  36. window.localStorage.removeItem('pending-store-name');
  37. } catch {
  38. // Nothing to forget when storage is blocked.
  39. }
  40. }
  41. export default function CreateStore({
  42. categories,
  43. languages,
  44. }: {
  45. categories: SelectOption[];
  46. languages: SelectOption[];
  47. }) {
  48. return (
  49. <>
  50. <Head title="Create store" />
  51. <div className="mx-auto w-full max-w-2xl space-y-6 p-4">
  52. <Heading
  53. title="Create a store"
  54. description="Tell us about your brand. The AI will use this to design your store."
  55. />
  56. <Form
  57. {...StoreController.store.form()}
  58. onSuccess={forgetPendingName}
  59. className="space-y-6"
  60. >
  61. {({ processing, errors }) => (
  62. <>
  63. <div className="grid gap-2">
  64. <Label htmlFor="name">Store name</Label>
  65. <Input
  66. id="name"
  67. name="name"
  68. required
  69. maxLength={60}
  70. autoFocus
  71. defaultValue={pendingName()}
  72. placeholder="e.g. Sambal Nenek"
  73. />
  74. <InputError message={errors.name} />
  75. </div>
  76. <div className="grid gap-6 sm:grid-cols-2">
  77. <div className="grid gap-2">
  78. <Label htmlFor="category">Category</Label>
  79. <select
  80. id="category"
  81. name="category"
  82. required
  83. defaultValue=""
  84. className={`${fieldClass} h-9 py-1`}
  85. >
  86. <option value="" disabled>
  87. Choose a category
  88. </option>
  89. {categories.map((category) => (
  90. <option
  91. key={category.value}
  92. value={category.value}
  93. >
  94. {category.label}
  95. </option>
  96. ))}
  97. </select>
  98. <InputError message={errors.category} />
  99. </div>
  100. <div className="grid gap-2">
  101. <Label htmlFor="language">
  102. Store language
  103. </Label>
  104. <select
  105. id="language"
  106. name="language"
  107. required
  108. defaultValue={languages[0]?.value}
  109. className={`${fieldClass} h-9 py-1`}
  110. >
  111. {languages.map((language) => (
  112. <option
  113. key={language.value}
  114. value={language.value}
  115. >
  116. {language.label}
  117. </option>
  118. ))}
  119. </select>
  120. <InputError message={errors.language} />
  121. </div>
  122. </div>
  123. <div className="grid gap-2">
  124. <Label htmlFor="description">
  125. Describe your brand
  126. </Label>
  127. <textarea
  128. id="description"
  129. name="description"
  130. required
  131. rows={5}
  132. maxLength={1000}
  133. className={fieldClass}
  134. placeholder="What do you sell, who is it for, and what feeling should the store give? e.g. Homemade sambal from a family recipe, premium, warm and traditional but modern."
  135. />
  136. <p className="text-xs text-muted-foreground">
  137. The more detail you give, the better the
  138. design.
  139. </p>
  140. <InputError message={errors.description} />
  141. </div>
  142. <div className="flex items-center gap-3">
  143. <Button
  144. disabled={processing}
  145. data-test="create-store-button"
  146. >
  147. Create store
  148. </Button>
  149. <Button variant="ghost" asChild>
  150. <Link href={dashboard()}>Cancel</Link>
  151. </Button>
  152. </div>
  153. </>
  154. )}
  155. </Form>
  156. </div>
  157. </>
  158. );
  159. }
  160. CreateStore.layout = {
  161. breadcrumbs: [
  162. {
  163. title: 'Dashboard',
  164. href: dashboard(),
  165. },
  166. {
  167. title: 'Create store',
  168. href: create(),
  169. },
  170. ],
  171. };