AI store generator for ecommerce, Malaysia first. Laravel 13 + React + TypeScript.
Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

security.tsx 5.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. import { Form, Head } from '@inertiajs/react';
  2. import { useRef } from 'react';
  3. import SecurityController from '@/actions/App/Http/Controllers/Settings/SecurityController';
  4. import Heading from '@/components/heading';
  5. import InputError from '@/components/input-error';
  6. import PasswordInput from '@/components/password-input';
  7. import { Button } from '@/components/ui/button';
  8. import { Label } from '@/components/ui/label';
  9. import { edit } from '@/routes/security';
  10. import type { Props as ManageTwoFactorProps } from '@/components/manage-two-factor';
  11. import ManageTwoFactor from '@/components/manage-two-factor';
  12. // oxfmt-ignore
  13. type Props = {
  14. passwordRules: string;
  15. } &
  16. ManageTwoFactorProps;
  17. export default function Security(props: Props) {
  18. const passwordInput = useRef<HTMLInputElement>(null);
  19. const currentPasswordInput = useRef<HTMLInputElement>(null);
  20. return (
  21. <>
  22. <Head title="Security settings" />
  23. <h1 className="sr-only">Security settings</h1>
  24. <div className="space-y-6">
  25. <Heading
  26. variant="small"
  27. title="Update password"
  28. description="Ensure your account is using a long, random password to stay secure"
  29. />
  30. <Form
  31. {...SecurityController.update.form()}
  32. options={{
  33. preserveScroll: true,
  34. }}
  35. resetOnError={[
  36. 'password',
  37. 'password_confirmation',
  38. 'current_password',
  39. ]}
  40. resetOnSuccess
  41. onError={(errors) => {
  42. if (errors.password) {
  43. passwordInput.current?.focus();
  44. }
  45. if (errors.current_password) {
  46. currentPasswordInput.current?.focus();
  47. }
  48. }}
  49. className="space-y-6"
  50. >
  51. {({ errors, processing }) => (
  52. <>
  53. <div className="grid gap-2">
  54. <Label htmlFor="current_password">
  55. Current password
  56. </Label>
  57. <PasswordInput
  58. id="current_password"
  59. ref={currentPasswordInput}
  60. name="current_password"
  61. className="mt-1 block w-full"
  62. autoComplete="current-password"
  63. placeholder="Current password"
  64. />
  65. <InputError message={errors.current_password} />
  66. </div>
  67. <div className="grid gap-2">
  68. <Label htmlFor="password">New password</Label>
  69. <PasswordInput
  70. id="password"
  71. ref={passwordInput}
  72. name="password"
  73. className="mt-1 block w-full"
  74. autoComplete="new-password"
  75. placeholder="New password"
  76. passwordrules={props.passwordRules}
  77. />
  78. <InputError message={errors.password} />
  79. </div>
  80. <div className="grid gap-2">
  81. <Label htmlFor="password_confirmation">
  82. Confirm password
  83. </Label>
  84. <PasswordInput
  85. id="password_confirmation"
  86. name="password_confirmation"
  87. className="mt-1 block w-full"
  88. autoComplete="new-password"
  89. placeholder="Confirm password"
  90. passwordrules={props.passwordRules}
  91. />
  92. <InputError
  93. message={errors.password_confirmation}
  94. />
  95. </div>
  96. <div className="flex items-center gap-4">
  97. <Button
  98. disabled={processing}
  99. data-test="update-password-button"
  100. >
  101. Save
  102. </Button>
  103. </div>
  104. </>
  105. )}
  106. </Form>
  107. </div>
  108. <ManageTwoFactor
  109. canManageTwoFactor={props.canManageTwoFactor}
  110. requiresConfirmation={props.requiresConfirmation}
  111. twoFactorEnabled={props.twoFactorEnabled}
  112. />
  113. </>
  114. );
  115. }
  116. Security.layout = {
  117. breadcrumbs: [
  118. {
  119. title: 'Security settings',
  120. href: edit(),
  121. },
  122. ],
  123. };