added some new pages
This commit is contained in:
1 parent
ab7fdf46b3
commit
f415acd649
40 files changed
+4022
-30
No files matched your search
@@ -81,7 +81,7 @@ src/
|
|||||||
- Create ve Edit sayfaları (`pages/`) sadece bu component'i çağıran birer **wrapper** olmalıdır.
|
- Create ve Edit sayfaları (`pages/`) sadece bu component'i çağıran birer **wrapper** olmalıdır.
|
||||||
- Edit sayfası `useParams()` ile URL'den `id` alır, ilgili hook ile veriyi fetch eder ve `initialData` prop'u olarak form'a geçer.
|
- Edit sayfası `useParams()` ile URL'den `id` alır, ilgili hook ile veriyi fetch eder ve `initialData` prop'u olarak form'a geçer.
|
||||||
- Validation, form state, submit logic — hepsi shared component içinde tek yerde yönetilir.
|
- Validation, form state, submit logic — hepsi shared component içinde tek yerde yönetilir.
|
||||||
- Create ve Edit form lar multiple form ise yani bir cok adimdan olusuyorsa o zaman `src/components/stepBarV2.tsx` componentini kullan. Çünkü orada Progressive Disclosure var. Ama eger sadece bir form ise o zaman `src/components/form.tsx` componentini kullan.
|
- Create ve Edit form lar multiple form ise yani bir cok adimdan olusuyorsa o zaman `src/components/stepBarV2.tsx` componentini kullan. Çünkü orada Progressive Disclosure var. Ama eger sadece bir form ise o zaman `src/components/formInput.tsx` componentini kullan.
|
||||||
- Örnek yapı:
|
- Örnek yapı:
|
||||||
```
|
```
|
||||||
features/[feature]/
|
features/[feature]/
|
||||||
|
|||||||
@@ -115,6 +115,28 @@ const ClientCreatePage = lazy(() => import("@/pages/users/clientsCreate"));
|
|||||||
const ClientViewPage = lazy(() => import("@/pages/users/clientsView"));
|
const ClientViewPage = lazy(() => import("@/pages/users/clientsView"));
|
||||||
const ClientEditPage = lazy(() => import("@/pages/users/clientsEdit"));
|
const ClientEditPage = lazy(() => import("@/pages/users/clientsEdit"));
|
||||||
|
|
||||||
|
const CurrencyRatesPage = lazy(() => import("@/pages/currencies/currencyRates"));
|
||||||
|
const CurrencyRateCreatePage = lazy(() => import("@/pages/currencies/currencyRatesCreate"));
|
||||||
|
const CurrencyRateViewPage = lazy(() => import("@/pages/currencies/currencyRatesView"));
|
||||||
|
const CurrencyRateEditPage = lazy(() => import("@/pages/currencies/currencyRatesEdit"));
|
||||||
|
|
||||||
|
const VisaMasterSberSettingsPage = lazy(() => import("@/pages/currencies/visaMasterSberSettings"));
|
||||||
|
const VisaMasterSberSettingCreatePage = lazy(() => import("@/pages/currencies/visaMasterSberSettingsCreate"));
|
||||||
|
const VisaMasterSberSettingEditPage = lazy(() => import("@/pages/currencies/visaMasterSberSettingsEdit"));
|
||||||
|
|
||||||
|
const OnlinePaymentsHistoryPage = lazy(() => import("@/pages/onlinePaymentsHistory"));
|
||||||
|
const OnlinePaymentsHistoryViewPage = lazy(() => import("@/pages/onlinePaymentsHistory/onlinePaymenHistoryView"));
|
||||||
|
|
||||||
|
const RolesPage = lazy(() => import("@/pages/settings/users/roles"));
|
||||||
|
const RoleCreatePage = lazy(() => import("@/pages/settings/users/createRole"));
|
||||||
|
const RoleViewPage = lazy(() => import("@/pages/settings/users/rolesView"));
|
||||||
|
const RoleEditPage = lazy(() => import("@/pages/settings/users/editRole"));
|
||||||
|
|
||||||
|
const PermissionsPage = lazy(() => import("@/pages/settings/users/permissions"));
|
||||||
|
const PermissionCreatePage = lazy(() => import("@/pages/settings/users/permissionsCreate"));
|
||||||
|
const PermissionsViewPage = lazy(() => import("@/pages/settings/users/permissionsView"));
|
||||||
|
const PermissionEditPage = lazy(() => import("@/pages/settings/users/permissionsEdit"));
|
||||||
|
|
||||||
function AuthGuard() {
|
function AuthGuard() {
|
||||||
const isAuthenticated = useAuthStore((s) => s.isAuthenticated);
|
const isAuthenticated = useAuthStore((s) => s.isAuthenticated);
|
||||||
if (!isAuthenticated) return <Navigate to="/login" replace />;
|
if (!isAuthenticated) return <Navigate to="/login" replace />;
|
||||||
@@ -595,6 +617,142 @@ export const router = createBrowserRouter([
|
|||||||
</Suspense>
|
</Suspense>
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
|
{ // Sidebar: /currencies-rates
|
||||||
|
path: "/currency-rates",
|
||||||
|
element: (
|
||||||
|
<Suspense fallback={<PageLoader />}>
|
||||||
|
<CurrencyRatesPage />
|
||||||
|
</Suspense>
|
||||||
|
),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: "/currency-rates/create",
|
||||||
|
element: (
|
||||||
|
<Suspense fallback={<PageLoader />}>
|
||||||
|
<CurrencyRateCreatePage />
|
||||||
|
</Suspense>
|
||||||
|
),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: "/currency-rates/:id",
|
||||||
|
element: (
|
||||||
|
<Suspense fallback={<PageLoader />}>
|
||||||
|
<CurrencyRateViewPage />
|
||||||
|
</Suspense>
|
||||||
|
),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: "/currency-rates/:id/edit",
|
||||||
|
element: (
|
||||||
|
<Suspense fallback={<PageLoader />}>
|
||||||
|
<CurrencyRateEditPage />
|
||||||
|
</Suspense>
|
||||||
|
),
|
||||||
|
},
|
||||||
|
{ // Sidebar: /visa-master-sber-settings
|
||||||
|
path: "/visa-master-sber-settings",
|
||||||
|
element: (
|
||||||
|
<Suspense fallback={<PageLoader />}>
|
||||||
|
<VisaMasterSberSettingsPage />
|
||||||
|
</Suspense>
|
||||||
|
),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: "/visa-master-sber-settings/create",
|
||||||
|
element: (
|
||||||
|
<Suspense fallback={<PageLoader />}>
|
||||||
|
<VisaMasterSberSettingCreatePage />
|
||||||
|
</Suspense>
|
||||||
|
),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: "/visa-master-sber-settings/:id/edit",
|
||||||
|
element: (
|
||||||
|
<Suspense fallback={<PageLoader />}>
|
||||||
|
<VisaMasterSberSettingEditPage />
|
||||||
|
</Suspense>
|
||||||
|
),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: "/online-payments-history",
|
||||||
|
element: (
|
||||||
|
<Suspense fallback={<PageLoader />}>
|
||||||
|
<OnlinePaymentsHistoryPage />
|
||||||
|
</Suspense>
|
||||||
|
),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: "/online-payments-history/:id",
|
||||||
|
element: (
|
||||||
|
<Suspense fallback={<PageLoader />}>
|
||||||
|
<OnlinePaymentsHistoryViewPage />
|
||||||
|
</Suspense>
|
||||||
|
),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: "/settings/users/roles",
|
||||||
|
element: (
|
||||||
|
<Suspense fallback={<PageLoader />}>
|
||||||
|
<RolesPage />
|
||||||
|
</Suspense>
|
||||||
|
),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: "/settings/users/roles/create",
|
||||||
|
element: (
|
||||||
|
<Suspense fallback={<PageLoader />}>
|
||||||
|
<RoleCreatePage />
|
||||||
|
</Suspense>
|
||||||
|
),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: "/settings/users/roles/:id",
|
||||||
|
element: (
|
||||||
|
<Suspense fallback={<PageLoader />}>
|
||||||
|
<RoleViewPage />
|
||||||
|
</Suspense>
|
||||||
|
),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: "/settings/users/roles/:id/edit",
|
||||||
|
element: (
|
||||||
|
<Suspense fallback={<PageLoader />}>
|
||||||
|
<RoleEditPage />
|
||||||
|
</Suspense>
|
||||||
|
),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: "/settings/users/permissions",
|
||||||
|
element: (
|
||||||
|
<Suspense fallback={<PageLoader />}>
|
||||||
|
<PermissionsPage />
|
||||||
|
</Suspense>
|
||||||
|
),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: "/settings/users/permissions/create",
|
||||||
|
element: (
|
||||||
|
<Suspense fallback={<PageLoader />}>
|
||||||
|
<PermissionCreatePage />
|
||||||
|
</Suspense>
|
||||||
|
),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: "/settings/users/permissions/:id",
|
||||||
|
element: (
|
||||||
|
<Suspense fallback={<PageLoader />}>
|
||||||
|
<PermissionsViewPage />
|
||||||
|
</Suspense>
|
||||||
|
),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: "/settings/users/permissions/:id/edit",
|
||||||
|
element: (
|
||||||
|
<Suspense fallback={<PageLoader />}>
|
||||||
|
<PermissionEditPage />
|
||||||
|
</Suspense>
|
||||||
|
),
|
||||||
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
|||||||
Binary file not shown.
|
Before Width: | Height: | Size: 13 KiB |
@@ -1 +0,0 @@
|
|||||||
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" class="iconify iconify--logos" width="35.93" height="32" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 228"><path fill="#00D8FF" d="M210.483 73.824a171.49 171.49 0 0 0-8.24-2.597c.465-1.9.893-3.777 1.273-5.621c6.238-30.281 2.16-54.676-11.769-62.708c-13.355-7.7-35.196.329-57.254 19.526a171.23 171.23 0 0 0-6.375 5.848a155.866 155.866 0 0 0-4.241-3.917C100.759 3.829 77.587-4.822 63.673 3.233C50.33 10.957 46.379 33.89 51.995 62.588a170.974 170.974 0 0 0 1.892 8.48c-3.28.932-6.445 1.924-9.474 2.98C17.309 83.498 0 98.307 0 113.668c0 15.865 18.582 31.778 46.812 41.427a145.52 145.52 0 0 0 6.921 2.165a167.467 167.467 0 0 0-2.01 9.138c-5.354 28.2-1.173 50.591 12.134 58.266c13.744 7.926 36.812-.22 59.273-19.855a145.567 145.567 0 0 0 5.342-4.923a168.064 168.064 0 0 0 6.92 6.314c21.758 18.722 43.246 26.282 56.54 18.586c13.731-7.949 18.194-32.003 12.4-61.268a145.016 145.016 0 0 0-1.535-6.842c1.62-.48 3.21-.974 4.76-1.488c29.348-9.723 48.443-25.443 48.443-41.52c0-15.417-17.868-30.326-45.517-39.844Zm-6.365 70.984c-1.4.463-2.836.91-4.3 1.345c-3.24-10.257-7.612-21.163-12.963-32.432c5.106-11 9.31-21.767 12.459-31.957c2.619.758 5.16 1.557 7.61 2.4c23.69 8.156 38.14 20.213 38.14 29.504c0 9.896-15.606 22.743-40.946 31.14Zm-10.514 20.834c2.562 12.94 2.927 24.64 1.23 33.787c-1.524 8.219-4.59 13.698-8.382 15.893c-8.067 4.67-25.32-1.4-43.927-17.412a156.726 156.726 0 0 1-6.437-5.87c7.214-7.889 14.423-17.06 21.459-27.246c12.376-1.098 24.068-2.894 34.671-5.345a134.17 134.17 0 0 1 1.386 6.193ZM87.276 214.515c-7.882 2.783-14.16 2.863-17.955.675c-8.075-4.657-11.432-22.636-6.853-46.752a156.923 156.923 0 0 1 1.869-8.499c10.486 2.32 22.093 3.988 34.498 4.994c7.084 9.967 14.501 19.128 21.976 27.15a134.668 134.668 0 0 1-4.877 4.492c-9.933 8.682-19.886 14.842-28.658 17.94ZM50.35 144.747c-12.483-4.267-22.792-9.812-29.858-15.863c-6.35-5.437-9.555-10.836-9.555-15.216c0-9.322 13.897-21.212 37.076-29.293c2.813-.98 5.757-1.905 8.812-2.773c3.204 10.42 7.406 21.315 12.477 32.332c-5.137 11.18-9.399 22.249-12.634 32.792a134.718 134.718 0 0 1-6.318-1.979Zm12.378-84.26c-4.811-24.587-1.616-43.134 6.425-47.789c8.564-4.958 27.502 2.111 47.463 19.835a144.318 144.318 0 0 1 3.841 3.545c-7.438 7.987-14.787 17.08-21.808 26.988c-12.04 1.116-23.565 2.908-34.161 5.309a160.342 160.342 0 0 1-1.76-7.887Zm110.427 27.268a347.8 347.8 0 0 0-7.785-12.803c8.168 1.033 15.994 2.404 23.343 4.08c-2.206 7.072-4.956 14.465-8.193 22.045a381.151 381.151 0 0 0-7.365-13.322Zm-45.032-43.861c5.044 5.465 10.096 11.566 15.065 18.186a322.04 322.04 0 0 0-30.257-.006c4.974-6.559 10.069-12.652 15.192-18.18ZM82.802 87.83a323.167 323.167 0 0 0-7.227 13.238c-3.184-7.553-5.909-14.98-8.134-22.152c7.304-1.634 15.093-2.97 23.209-3.984a321.524 321.524 0 0 0-7.848 12.897Zm8.081 65.352c-8.385-.936-16.291-2.203-23.593-3.793c2.26-7.3 5.045-14.885 8.298-22.6a321.187 321.187 0 0 0 7.257 13.246c2.594 4.48 5.28 8.868 8.038 13.147Zm37.542 31.03c-5.184-5.592-10.354-11.779-15.403-18.433c4.902.192 9.899.29 14.978.29c5.218 0 10.376-.117 15.453-.343c-4.985 6.774-10.018 12.97-15.028 18.486Zm52.198-57.817c3.422 7.8 6.306 15.345 8.596 22.52c-7.422 1.694-15.436 3.058-23.88 4.071a382.417 382.417 0 0 0 7.859-13.026a347.403 347.403 0 0 0 7.425-13.565Zm-16.898 8.101a358.557 358.557 0 0 1-12.281 19.815a329.4 329.4 0 0 1-23.444.823c-7.967 0-15.716-.248-23.178-.732a310.202 310.202 0 0 1-12.513-19.846h.001a307.41 307.41 0 0 1-10.923-20.627a310.278 310.278 0 0 1 10.89-20.637l-.001.001a307.318 307.318 0 0 1 12.413-19.761c7.613-.576 15.42-.876 23.31-.876H128c7.926 0 15.743.303 23.354.883a329.357 329.357 0 0 1 12.335 19.695a358.489 358.489 0 0 1 11.036 20.54a329.472 329.472 0 0 1-11 20.722Zm22.56-122.124c8.572 4.944 11.906 24.881 6.52 51.026c-.344 1.668-.73 3.367-1.15 5.09c-10.622-2.452-22.155-4.275-34.23-5.408c-7.034-10.017-14.323-19.124-21.64-27.008a160.789 160.789 0 0 1 5.888-5.4c18.9-16.447 36.564-22.941 44.612-18.3ZM128 90.808c12.625 0 22.86 10.235 22.86 22.86s-10.235 22.86-22.86 22.86s-22.86-10.235-22.86-22.86s10.235-22.86 22.86-22.86Z"></path></svg>
|
|
||||||
|
Before Width: | Height: | Size: 4.0 KiB |
@@ -1 +0,0 @@
|
|||||||
<svg xmlns="http://www.w3.org/2000/svg" width="77" height="47" fill="none" aria-labelledby="vite-logo-title" viewBox="0 0 77 47"><title id="vite-logo-title">Vite</title><style>.parenthesis{fill:#000}@media (prefers-color-scheme:dark){.parenthesis{fill:#fff}}</style><path fill="#9135ff" d="M40.151 45.71c-.663.844-2.02.374-2.02-.699V34.708a2.26 2.26 0 0 0-2.262-2.262H24.493c-.92 0-1.457-1.04-.92-1.788l7.479-10.471c1.07-1.498 0-3.578-1.842-3.578H15.443c-.92 0-1.456-1.04-.92-1.788l9.696-13.576c.213-.297.556-.474.92-.474h28.894c.92 0 1.456 1.04.92 1.788l-7.48 10.472c-1.07 1.497 0 3.578 1.842 3.578h11.376c.944 0 1.474 1.087.89 1.83L40.153 45.712z"/><mask id="a" width="48" height="47" x="14" y="0" maskUnits="userSpaceOnUse" style="mask-type:alpha"><path fill="#000" d="M40.047 45.71c-.663.843-2.02.374-2.02-.699V34.708a2.26 2.26 0 0 0-2.262-2.262H24.389c-.92 0-1.457-1.04-.92-1.788l7.479-10.472c1.07-1.497 0-3.578-1.842-3.578H15.34c-.92 0-1.456-1.04-.92-1.788l9.696-13.575c.213-.297.556-.474.92-.474H53.93c.92 0 1.456 1.04.92 1.788L47.37 13.03c-1.07 1.498 0 3.578 1.842 3.578h11.376c.944 0 1.474 1.088.89 1.831L40.049 45.712z"/></mask><g mask="url(#a)"><g filter="url(#b)"><ellipse cx="5.508" cy="14.704" fill="#eee6ff" rx="5.508" ry="14.704" transform="rotate(269.814 20.96 11.29)scale(-1 1)"/></g><g filter="url(#c)"><ellipse cx="10.399" cy="29.851" fill="#eee6ff" rx="10.399" ry="29.851" transform="rotate(89.814 -16.902 -8.275)scale(1 -1)"/></g><g filter="url(#d)"><ellipse cx="5.508" cy="30.487" fill="#8900ff" rx="5.508" ry="30.487" transform="rotate(89.814 -19.197 -7.127)scale(1 -1)"/></g><g filter="url(#e)"><ellipse cx="5.508" cy="30.599" fill="#8900ff" rx="5.508" ry="30.599" transform="rotate(89.814 -25.928 4.177)scale(1 -1)"/></g><g filter="url(#f)"><ellipse cx="5.508" cy="30.599" fill="#8900ff" rx="5.508" ry="30.599" transform="rotate(89.814 -25.738 5.52)scale(1 -1)"/></g><g filter="url(#g)"><ellipse cx="14.072" cy="22.078" fill="#eee6ff" rx="14.072" ry="22.078" transform="rotate(93.35 31.245 55.578)scale(-1 1)"/></g><g filter="url(#h)"><ellipse cx="3.47" cy="21.501" fill="#8900ff" rx="3.47" ry="21.501" transform="rotate(89.009 35.419 55.202)scale(-1 1)"/></g><g filter="url(#i)"><ellipse cx="3.47" cy="21.501" fill="#8900ff" rx="3.47" ry="21.501" transform="rotate(89.009 35.419 55.202)scale(-1 1)"/></g><g filter="url(#j)"><ellipse cx="14.592" cy="9.743" fill="#8900ff" rx="4.407" ry="29.108" transform="rotate(39.51 14.592 9.743)"/></g><g filter="url(#k)"><ellipse cx="61.728" cy="-5.321" fill="#8900ff" rx="4.407" ry="29.108" transform="rotate(37.892 61.728 -5.32)"/></g><g filter="url(#l)"><ellipse cx="55.618" cy="7.104" fill="#00c2ff" rx="5.971" ry="9.665" transform="rotate(37.892 55.618 7.104)"/></g><g filter="url(#m)"><ellipse cx="12.326" cy="39.103" fill="#8900ff" rx="4.407" ry="29.108" transform="rotate(37.892 12.326 39.103)"/></g><g filter="url(#n)"><ellipse cx="12.326" cy="39.103" fill="#8900ff" rx="4.407" ry="29.108" transform="rotate(37.892 12.326 39.103)"/></g><g filter="url(#o)"><ellipse cx="49.857" cy="30.678" fill="#8900ff" rx="4.407" ry="29.108" transform="rotate(37.892 49.857 30.678)"/></g><g filter="url(#p)"><ellipse cx="52.623" cy="33.171" fill="#00c2ff" rx="5.971" ry="15.297" transform="rotate(37.892 52.623 33.17)"/></g></g><path d="M6.919 0c-9.198 13.166-9.252 33.575 0 46.789h6.215c-9.25-13.214-9.196-33.623 0-46.789zm62.424 0h-6.215c9.198 13.166 9.252 33.575 0 46.789h6.215c9.25-13.214 9.196-33.623 0-46.789" class="parenthesis"/><defs><filter id="b" width="60.045" height="41.654" x="-5.564" y="16.92" color-interpolation-filters="sRGB" filterUnits="userSpaceOnUse"><feFlood flood-opacity="0" result="BackgroundImageFix"/><feBlend in="SourceGraphic" in2="BackgroundImageFix" result="shape"/><feGaussianBlur result="effect1_foregroundBlur_2002_17286" stdDeviation="7.659"/></filter><filter id="c" width="90.34" height="51.437" x="-40.407" y="-6.762" color-interpolation-filters="sRGB" filterUnits="userSpaceOnUse"><feFlood flood-opacity="0" result="BackgroundImageFix"/><feBlend in="SourceGraphic" in2="BackgroundImageFix" result="shape"/><feGaussianBlur result="effect1_foregroundBlur_2002_17286" stdDeviation="7.659"/></filter><filter id="d" width="79.355" height="29.4" x="-35.435" y="2.801" color-interpolation-filters="sRGB" filterUnits="userSpaceOnUse"><feFlood flood-opacity="0" result="BackgroundImageFix"/><feBlend in="SourceGraphic" in2="BackgroundImageFix" result="shape"/><feGaussianBlur result="effect1_foregroundBlur_2002_17286" stdDeviation="4.596"/></filter><filter id="e" width="79.579" height="29.4" x="-30.84" y="20.8" color-interpolation-filters="sRGB" filterUnits="userSpaceOnUse"><feFlood flood-opacity="0" result="BackgroundImageFix"/><feBlend in="SourceGraphic" in2="BackgroundImageFix" result="shape"/><feGaussianBlur result="effect1_foregroundBlur_2002_17286" stdDeviation="4.596"/></filter><filter id="f" width="79.579" height="29.4" x="-29.307" y="21.949" color-interpolation-filters="sRGB" filterUnits="usLine truncated
|
|
||||||
|
Before Width: | Height: | Size: 8.5 KiB |
@@ -655,6 +655,7 @@ function FileInput({
|
|||||||
<ErrorMsg error={error} />
|
<ErrorMsg error={error} />
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ─── FormInput (router) ───────────────────────────────────────────────────────
|
// ─── FormInput (router) ───────────────────────────────────────────────────────
|
||||||
|
|||||||
@@ -0,0 +1,141 @@
|
|||||||
|
// features/currencyRates/api/currencyRatesApi.ts
|
||||||
|
|
||||||
|
export type CurrencyCode = 'USD' | 'RUB' | 'TMT' | 'EUR' | 'GBP' | 'CNY' | 'TRY'
|
||||||
|
|
||||||
|
export interface CurrencyRate {
|
||||||
|
id: number
|
||||||
|
currencyFrom: CurrencyCode
|
||||||
|
currencyTo: CurrencyCode
|
||||||
|
value: number
|
||||||
|
createdAt: string
|
||||||
|
updatedAt: string
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface CurrencyRateListParams {
|
||||||
|
page?: number
|
||||||
|
perPage?: number
|
||||||
|
search?: string
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface CurrencyRateListResponse {
|
||||||
|
data: CurrencyRate[]
|
||||||
|
total: number
|
||||||
|
page: number
|
||||||
|
perPage: number
|
||||||
|
totalPages: number
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface CreateCurrencyRatePayload {
|
||||||
|
currencyFrom: CurrencyCode
|
||||||
|
currencyTo: CurrencyCode
|
||||||
|
value: number
|
||||||
|
}
|
||||||
|
|
||||||
|
export type UpdateCurrencyRatePayload = CreateCurrencyRatePayload
|
||||||
|
|
||||||
|
// ─── Mock Data ────────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
|
const MOCK_RATES: CurrencyRate[] = [
|
||||||
|
{ id: 6, currencyFrom: 'USD', currencyTo: 'USD', value: 250, createdAt: '2026-04-01T10:00:00Z', updatedAt: '2026-05-01T10:00:00Z' },
|
||||||
|
{ id: 5, currencyFrom: 'RUB', currencyTo: 'TMT', value: 0.047504, createdAt: '2026-03-15T08:30:00Z', updatedAt: '2026-05-10T08:30:00Z' },
|
||||||
|
{ id: 4, currencyFrom: 'USD', currencyTo: 'RUB', value: 74.0455, createdAt: '2026-02-20T14:00:00Z', updatedAt: '2026-05-08T14:00:00Z' },
|
||||||
|
{ id: 2, currencyFrom: 'USD', currencyTo: 'TMT', value: 3.5175, createdAt: '2026-01-10T09:00:00Z', updatedAt: '2026-05-05T09:00:00Z' },
|
||||||
|
{ id: 1, currencyFrom: 'EUR', currencyTo: 'TMT', value: 3.8120, createdAt: '2026-01-05T09:00:00Z', updatedAt: '2026-05-03T09:00:00Z' },
|
||||||
|
{ id: 3, currencyFrom: 'EUR', currencyTo: 'RUB', value: 80.2300, createdAt: '2026-01-12T11:00:00Z', updatedAt: '2026-04-28T11:00:00Z' },
|
||||||
|
{ id: 7, currencyFrom: 'GBP', currencyTo: 'TMT', value: 4.4500, createdAt: '2026-04-10T13:00:00Z', updatedAt: '2026-05-11T13:00:00Z' },
|
||||||
|
{ id: 8, currencyFrom: 'CNY', currencyTo: 'TMT', value: 0.4850, createdAt: '2026-04-15T10:00:00Z', updatedAt: '2026-05-09T10:00:00Z' },
|
||||||
|
]
|
||||||
|
|
||||||
|
let mockStore: CurrencyRate[] = [...MOCK_RATES]
|
||||||
|
let nextId = 9
|
||||||
|
|
||||||
|
const delay = (ms = 400) => new Promise<void>((res) => setTimeout(res, ms))
|
||||||
|
|
||||||
|
// ─── API Functions ────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
|
export async function fetchCurrencyRates(
|
||||||
|
params: CurrencyRateListParams = {}
|
||||||
|
): Promise<CurrencyRateListResponse> {
|
||||||
|
await delay()
|
||||||
|
const { page = 1, perPage = 25, search = '' } = params
|
||||||
|
|
||||||
|
let filtered = [...mockStore]
|
||||||
|
|
||||||
|
if (search.trim()) {
|
||||||
|
const q = search.toLowerCase()
|
||||||
|
filtered = filtered.filter(
|
||||||
|
(r) =>
|
||||||
|
r.currencyFrom.toLowerCase().includes(q) ||
|
||||||
|
r.currencyTo.toLowerCase().includes(q) ||
|
||||||
|
String(r.value).includes(q) ||
|
||||||
|
String(r.id).includes(q)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Sort by id desc
|
||||||
|
filtered.sort((a, b) => b.id - a.id)
|
||||||
|
|
||||||
|
const total = filtered.length
|
||||||
|
const totalPages = Math.ceil(total / perPage)
|
||||||
|
const start = (page - 1) * perPage
|
||||||
|
const data = filtered.slice(start, start + perPage)
|
||||||
|
|
||||||
|
return { data, total, page, perPage, totalPages }
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function fetchCurrencyRateById(id: number): Promise<CurrencyRate> {
|
||||||
|
await delay()
|
||||||
|
const rate = mockStore.find((r) => r.id === id)
|
||||||
|
if (!rate) throw new Error(`Currency rate with id ${id} not found`)
|
||||||
|
return { ...rate }
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function createCurrencyRate(
|
||||||
|
payload: CreateCurrencyRatePayload
|
||||||
|
): Promise<CurrencyRate> {
|
||||||
|
await delay()
|
||||||
|
const now = new Date().toISOString()
|
||||||
|
const newRate: CurrencyRate = {
|
||||||
|
id: nextId++,
|
||||||
|
...payload,
|
||||||
|
createdAt: now,
|
||||||
|
updatedAt: now,
|
||||||
|
}
|
||||||
|
mockStore = [newRate, ...mockStore]
|
||||||
|
return newRate
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function updateCurrencyRate(
|
||||||
|
id: number,
|
||||||
|
payload: UpdateCurrencyRatePayload
|
||||||
|
): Promise<CurrencyRate> {
|
||||||
|
await delay()
|
||||||
|
const idx = mockStore.findIndex((r) => r.id === id)
|
||||||
|
if (idx === -1) throw new Error(`Currency rate with id ${id} not found`)
|
||||||
|
const updated: CurrencyRate = {
|
||||||
|
...mockStore[idx],
|
||||||
|
...payload,
|
||||||
|
updatedAt: new Date().toISOString(),
|
||||||
|
}
|
||||||
|
mockStore = mockStore.map((r) => (r.id === id ? updated : r))
|
||||||
|
return updated
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function deleteCurrencyRate(id: number): Promise<void> {
|
||||||
|
await delay()
|
||||||
|
const exists = mockStore.some((r) => r.id === id)
|
||||||
|
if (!exists) throw new Error(`Currency rate with id ${id} not found`)
|
||||||
|
mockStore = mockStore.filter((r) => r.id !== id)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ─── Constants ────────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
|
export const CURRENCY_OPTIONS: { value: CurrencyCode; label: string }[] = [
|
||||||
|
{ value: 'USD', label: 'USD — US Dollar' },
|
||||||
|
{ value: 'RUB', label: 'RUB — Russian Ruble' },
|
||||||
|
{ value: 'TMT', label: 'TMT — Turkmen Manat' },
|
||||||
|
{ value: 'EUR', label: 'EUR — Euro' },
|
||||||
|
{ value: 'GBP', label: 'GBP — British Pound' },
|
||||||
|
{ value: 'CNY', label: 'CNY — Chinese Yuan' },
|
||||||
|
{ value: 'TRY', label: 'TRY — Turkish Lira' },
|
||||||
|
]
|
||||||
@@ -0,0 +1,203 @@
|
|||||||
|
// features/currencyRates/components/CurrencyRateForm.tsx
|
||||||
|
|
||||||
|
import { useEffect, useState } from 'react'
|
||||||
|
import { useNavigate } from 'react-router-dom'
|
||||||
|
import { useTranslation } from 'react-i18next'
|
||||||
|
import { FormInput } from '@/components/formInput'
|
||||||
|
import { Button } from '@/components/ui/button'
|
||||||
|
import { CURRENCY_OPTIONS, type CurrencyCode, type CurrencyRate } from '../api/currencyRatesApi'
|
||||||
|
import { useCreateCurrencyRate, useUpdateCurrencyRate } from '../hooks/useCurrencyRates'
|
||||||
|
|
||||||
|
// ─── Types ────────────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
|
interface FormState {
|
||||||
|
currencyFrom: string
|
||||||
|
currencyTo: string
|
||||||
|
value: string
|
||||||
|
}
|
||||||
|
|
||||||
|
interface FormErrors {
|
||||||
|
currencyFrom?: string
|
||||||
|
currencyTo?: string
|
||||||
|
value?: string
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface CurrencyRateFormProps {
|
||||||
|
mode: 'create' | 'edit'
|
||||||
|
initialData?: CurrencyRate
|
||||||
|
rateId?: number
|
||||||
|
}
|
||||||
|
|
||||||
|
// ─── Validation ───────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
|
function validate(form: FormState, t: (key: string, fallback: string) => string): FormErrors {
|
||||||
|
const errors: FormErrors = {}
|
||||||
|
|
||||||
|
if (!form.currencyFrom) {
|
||||||
|
errors.currencyFrom = t('currencyRates.errors.currencyFromRequired', 'Walýuta saýlaň')
|
||||||
|
}
|
||||||
|
if (!form.currencyTo) {
|
||||||
|
errors.currencyTo = t('currencyRates.errors.currencyToRequired', 'Walýuta saýlaň')
|
||||||
|
}
|
||||||
|
if (!form.value.trim()) {
|
||||||
|
errors.value = t('currencyRates.errors.valueRequired', 'Bahany giriziň')
|
||||||
|
} else if (isNaN(Number(form.value)) || Number(form.value) <= 0) {
|
||||||
|
errors.value = t('currencyRates.errors.valueInvalid', 'Baha 0-dan uly bolmaly')
|
||||||
|
}
|
||||||
|
|
||||||
|
return errors
|
||||||
|
}
|
||||||
|
|
||||||
|
// ─── CurrencyRateForm ─────────────────────────────────────────────────────────
|
||||||
|
|
||||||
|
export function CurrencyRateForm({ mode, initialData, rateId }: CurrencyRateFormProps) {
|
||||||
|
const { t } = useTranslation()
|
||||||
|
const navigate = useNavigate()
|
||||||
|
|
||||||
|
const [form, setForm] = useState<FormState>({
|
||||||
|
currencyFrom: initialData?.currencyFrom ?? '',
|
||||||
|
currencyTo: initialData?.currencyTo ?? '',
|
||||||
|
value: initialData?.value != null ? String(initialData.value) : '',
|
||||||
|
})
|
||||||
|
const [errors, setErrors] = useState<FormErrors>({})
|
||||||
|
|
||||||
|
const createMutation = useCreateCurrencyRate()
|
||||||
|
const updateMutation = useUpdateCurrencyRate(rateId ?? 0)
|
||||||
|
|
||||||
|
const isPending = createMutation.isPending || updateMutation.isPending
|
||||||
|
|
||||||
|
// Sync form when initialData loads (edit mode)
|
||||||
|
useEffect(() => {
|
||||||
|
if (mode === 'edit' && initialData) {
|
||||||
|
setForm({
|
||||||
|
currencyFrom: initialData.currencyFrom,
|
||||||
|
currencyTo: initialData.currencyTo,
|
||||||
|
value: String(initialData.value),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}, [mode, initialData])
|
||||||
|
|
||||||
|
const setField = (field: keyof FormState) => (val: string) => {
|
||||||
|
setForm((prev) => ({ ...prev, [field]: val }))
|
||||||
|
// Clear error on change
|
||||||
|
if (errors[field]) setErrors((prev) => ({ ...prev, [field]: undefined }))
|
||||||
|
}
|
||||||
|
|
||||||
|
const handleSubmit = async () => {
|
||||||
|
const validationErrors = validate(form, t)
|
||||||
|
if (Object.keys(validationErrors).length > 0) {
|
||||||
|
setErrors(validationErrors)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
const payload = {
|
||||||
|
currencyFrom: form.currencyFrom as CurrencyCode,
|
||||||
|
currencyTo: form.currencyTo as CurrencyCode,
|
||||||
|
value: Number(form.value),
|
||||||
|
}
|
||||||
|
|
||||||
|
if (mode === 'create') {
|
||||||
|
await createMutation.mutateAsync(payload)
|
||||||
|
navigate('/resources/currency-rates')
|
||||||
|
} else {
|
||||||
|
await updateMutation.mutateAsync(payload)
|
||||||
|
navigate(`/resources/currency-rates/${rateId}`)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const handleCancel = () => {
|
||||||
|
if (mode === 'create') {
|
||||||
|
navigate('/resources/currency-rates')
|
||||||
|
} else {
|
||||||
|
navigate(`/resources/currency-rates/${rateId}`)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="space-y-6">
|
||||||
|
{/* Currency From */}
|
||||||
|
<div className="grid grid-cols-[220px_1fr] items-start py-4 px-6 border-b border-border">
|
||||||
|
<label className="text-sm text-muted-foreground pt-1.5">
|
||||||
|
{t('currencyRates.fields.currencyFrom', 'Currency from')}
|
||||||
|
<span className="text-destructive ml-0.5">*</span>
|
||||||
|
</label>
|
||||||
|
<div className="space-y-1">
|
||||||
|
<FormInput
|
||||||
|
type="searchable-select"
|
||||||
|
value={form.currencyFrom}
|
||||||
|
onChange={setField('currencyFrom')}
|
||||||
|
options={CURRENCY_OPTIONS}
|
||||||
|
placeholder={t('common.selectPlaceholder', 'Saýlamak üçin basyň')}
|
||||||
|
error={errors.currencyFrom}
|
||||||
|
disabled={isPending}
|
||||||
|
/>
|
||||||
|
<p className="text-xs text-muted-foreground">
|
||||||
|
{t('currencyRates.hints.oneUnit', '1 möçberi')}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Currency To */}
|
||||||
|
<div className="grid grid-cols-[220px_1fr] items-start py-4 px-6 border-b border-border">
|
||||||
|
<label className="text-sm text-muted-foreground pt-1.5">
|
||||||
|
{t('currencyRates.fields.currencyTo', 'Currency to')}
|
||||||
|
<span className="text-destructive ml-0.5">*</span>
|
||||||
|
</label>
|
||||||
|
<FormInput
|
||||||
|
type="searchable-select"
|
||||||
|
value={form.currencyTo}
|
||||||
|
onChange={setField('currencyTo')}
|
||||||
|
options={CURRENCY_OPTIONS}
|
||||||
|
placeholder={t('common.selectPlaceholder', 'Saýlamak üçin basyň')}
|
||||||
|
error={errors.currencyTo}
|
||||||
|
disabled={isPending}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Value */}
|
||||||
|
<div className="grid grid-cols-[220px_1fr] items-start py-4 px-6">
|
||||||
|
<label className="text-sm text-muted-foreground pt-1.5">
|
||||||
|
{t('currencyRates.fields.value', 'Value')}
|
||||||
|
<span className="text-destructive ml-0.5">*</span>
|
||||||
|
</label>
|
||||||
|
<div className="space-y-1">
|
||||||
|
<FormInput
|
||||||
|
type="number"
|
||||||
|
value={form.value}
|
||||||
|
onChange={setField('value')}
|
||||||
|
placeholder={t('currencyRates.fields.value', 'Value')}
|
||||||
|
error={errors.value}
|
||||||
|
disabled={isPending}
|
||||||
|
/>
|
||||||
|
<p className="text-xs text-muted-foreground italic">
|
||||||
|
{t('currencyRates.hints.decimalNote', 'Bitin däl sanlary "." bilen ýazmaly')}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Footer Actions */}
|
||||||
|
<div className="flex items-center justify-end gap-3 px-6 py-4 border-t border-border">
|
||||||
|
<Button
|
||||||
|
type="button"
|
||||||
|
variant="ghost"
|
||||||
|
onClick={handleCancel}
|
||||||
|
disabled={isPending}
|
||||||
|
>
|
||||||
|
{t('common.cancel', 'Ýatyr')}
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
type="button"
|
||||||
|
onClick={handleSubmit}
|
||||||
|
disabled={isPending}
|
||||||
|
className="bg-primary text-primary-foreground hover:bg-primary/90"
|
||||||
|
>
|
||||||
|
{isPending
|
||||||
|
? t('common.saving', 'Saklanýar...')
|
||||||
|
: mode === 'create'
|
||||||
|
? t('currencyRates.actions.create', 'Walýuta kursy dörediň')
|
||||||
|
: t('currencyRates.actions.update', 'Ýatda sakla')}
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -0,0 +1,100 @@
|
|||||||
|
// features/currencyRates/hooks/useCurrencyRates.ts
|
||||||
|
|
||||||
|
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query'
|
||||||
|
import { toast } from 'sonner'
|
||||||
|
import { useTranslation } from 'react-i18next'
|
||||||
|
import {
|
||||||
|
fetchCurrencyRates,
|
||||||
|
fetchCurrencyRateById,
|
||||||
|
createCurrencyRate,
|
||||||
|
updateCurrencyRate,
|
||||||
|
deleteCurrencyRate,
|
||||||
|
type CurrencyRateListParams,
|
||||||
|
type CreateCurrencyRatePayload,
|
||||||
|
type UpdateCurrencyRatePayload,
|
||||||
|
} from '../api/currencyRatesApi'
|
||||||
|
|
||||||
|
// ─── Query Keys ───────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
|
export const currencyRateKeys = {
|
||||||
|
all: ['currencyRates'] as const,
|
||||||
|
lists: () => [...currencyRateKeys.all, 'list'] as const,
|
||||||
|
list: (params: CurrencyRateListParams) =>
|
||||||
|
[...currencyRateKeys.lists(), params] as const,
|
||||||
|
detail: (id: number) =>
|
||||||
|
[...currencyRateKeys.all, 'detail', id] as const,
|
||||||
|
}
|
||||||
|
|
||||||
|
// ─── useGetCurrencyRates ──────────────────────────────────────────────────────
|
||||||
|
|
||||||
|
export function useGetCurrencyRates(params: CurrencyRateListParams = {}) {
|
||||||
|
return useQuery({
|
||||||
|
queryKey: currencyRateKeys.list(params),
|
||||||
|
queryFn: () => fetchCurrencyRates(params),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// ─── useGetCurrencyRateById ───────────────────────────────────────────────────
|
||||||
|
|
||||||
|
export function useGetCurrencyRateById(id: number) {
|
||||||
|
return useQuery({
|
||||||
|
queryKey: currencyRateKeys.detail(id),
|
||||||
|
queryFn: () => fetchCurrencyRateById(id),
|
||||||
|
enabled: !!id,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// ─── useCreateCurrencyRate ────────────────────────────────────────────────────
|
||||||
|
|
||||||
|
export function useCreateCurrencyRate() {
|
||||||
|
const queryClient = useQueryClient()
|
||||||
|
const { t } = useTranslation()
|
||||||
|
|
||||||
|
return useMutation({
|
||||||
|
mutationFn: (payload: CreateCurrencyRatePayload) => createCurrencyRate(payload),
|
||||||
|
onSuccess: () => {
|
||||||
|
queryClient.invalidateQueries({ queryKey: currencyRateKeys.lists() })
|
||||||
|
toast.success(t('currencyRates.toast.created', 'Walýuta kursy döredildi'))
|
||||||
|
},
|
||||||
|
onError: () => {
|
||||||
|
toast.error(t('currencyRates.toast.createError', 'Döretmek başartmady'))
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// ─── useUpdateCurrencyRate ────────────────────────────────────────────────────
|
||||||
|
|
||||||
|
export function useUpdateCurrencyRate(id: number) {
|
||||||
|
const queryClient = useQueryClient()
|
||||||
|
const { t } = useTranslation()
|
||||||
|
|
||||||
|
return useMutation({
|
||||||
|
mutationFn: (payload: UpdateCurrencyRatePayload) => updateCurrencyRate(id, payload),
|
||||||
|
onSuccess: () => {
|
||||||
|
queryClient.invalidateQueries({ queryKey: currencyRateKeys.lists() })
|
||||||
|
queryClient.invalidateQueries({ queryKey: currencyRateKeys.detail(id) })
|
||||||
|
toast.success(t('currencyRates.toast.updated', 'Walýuta kursy üýtgedildi'))
|
||||||
|
},
|
||||||
|
onError: () => {
|
||||||
|
toast.error(t('currencyRates.toast.updateError', 'Üýtgetmek başartmady'))
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// ─── useDeleteCurrencyRate ────────────────────────────────────────────────────
|
||||||
|
|
||||||
|
export function useDeleteCurrencyRate() {
|
||||||
|
const queryClient = useQueryClient()
|
||||||
|
const { t } = useTranslation()
|
||||||
|
|
||||||
|
return useMutation({
|
||||||
|
mutationFn: (id: number) => deleteCurrencyRate(id),
|
||||||
|
onSuccess: () => {
|
||||||
|
queryClient.invalidateQueries({ queryKey: currencyRateKeys.lists() })
|
||||||
|
toast.success(t('currencyRates.toast.deleted', 'Walýuta kursy pozuldy'))
|
||||||
|
},
|
||||||
|
onError: () => {
|
||||||
|
toast.error(t('currencyRates.toast.deleteError', 'Pozmak başartmady'))
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
@@ -0,0 +1,151 @@
|
|||||||
|
// features/onlinePaymentHistory/api/onlinePaymentHistoryApi.ts
|
||||||
|
|
||||||
|
export type PaymentStatus = 'GARAŞYLÝAR' | 'TÖLENEN' | 'YATYRYLAN'
|
||||||
|
|
||||||
|
export interface OnlinePayment {
|
||||||
|
id: number
|
||||||
|
orderId: string
|
||||||
|
amount: number
|
||||||
|
orderNumber: string
|
||||||
|
apiClient: string
|
||||||
|
description: string
|
||||||
|
formUrl: string
|
||||||
|
successUrl: string
|
||||||
|
status: PaymentStatus
|
||||||
|
callbackStatus: string | null
|
||||||
|
username: string
|
||||||
|
onlinePaymantableId: number
|
||||||
|
onlinePaymantableType: string
|
||||||
|
createdAt: string
|
||||||
|
updatedAt: string
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface OnlinePaymentListParams {
|
||||||
|
page?: number
|
||||||
|
perPage?: number
|
||||||
|
search?: string
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface OnlinePaymentListResponse {
|
||||||
|
data: OnlinePayment[]
|
||||||
|
total: number
|
||||||
|
page: number
|
||||||
|
perPage: number
|
||||||
|
totalPages: number
|
||||||
|
}
|
||||||
|
|
||||||
|
// ─── Mock Data ────────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
|
const buildPayment = (
|
||||||
|
id: number,
|
||||||
|
orderId: string,
|
||||||
|
amount: number,
|
||||||
|
orderNumber: string,
|
||||||
|
apiClient: string,
|
||||||
|
description: string,
|
||||||
|
status: PaymentStatus,
|
||||||
|
username: string,
|
||||||
|
paymantableId: number,
|
||||||
|
paymantableType: string,
|
||||||
|
createdAt: string,
|
||||||
|
callbackStatus: string | null = null
|
||||||
|
): OnlinePayment => ({
|
||||||
|
id,
|
||||||
|
orderId,
|
||||||
|
amount,
|
||||||
|
orderNumber,
|
||||||
|
apiClient,
|
||||||
|
description,
|
||||||
|
formUrl: `https://mpi.gov.tm/payment/merchants/online/payment_ru.html?mdOrder=${orderId}`,
|
||||||
|
successUrl: 'https://online.tbbank.gov.tm/online-payment-store-visa-master',
|
||||||
|
status,
|
||||||
|
callbackStatus,
|
||||||
|
username,
|
||||||
|
onlinePaymantableId: paymantableId,
|
||||||
|
onlinePaymantableType: paymantableType,
|
||||||
|
createdAt,
|
||||||
|
updatedAt: createdAt,
|
||||||
|
})
|
||||||
|
|
||||||
|
const VM_TYPE = 'App\\Modules\\VisaMasterPaymentOrder\\Models\\VisaMasterPaymentOrder'
|
||||||
|
const SBER_TYPE = 'App\\Modules\\SberPaymentOrder\\Models\\SberPaymentOrder'
|
||||||
|
const KART_TYPE = 'App\\Modules\\KartPaymentOrder\\Models\\KartPaymentOrder'
|
||||||
|
|
||||||
|
const MOCK_PAYMENTS: OnlinePayment[] = [
|
||||||
|
buildPayment(1667, 'ed99d307-65fd-40ed-98ec-898019000af4', 99438, '110526160855', 'billing_visa_master_username', 'Visa/Master tölegi', 'GARAŞYLÝAR', '10130100040830', 5280, VM_TYPE, '2026-05-11T16:08:00Z'),
|
||||||
|
buildPayment(1666, 'ab12c456-11aa-22bb-33cc-111111000001', 99438, '110526160800', 'billing_visa_master_username', 'Visa/Master tölegi', 'TÖLENEN', '10130100040830', 5279, VM_TYPE, '2026-05-11T16:06:00Z', 'SUCCESS'),
|
||||||
|
buildPayment(1665, 'bc23d567-22bb-33cc-44dd-222222000002', 99438, '110526160745', 'billing_visa_master_username', 'Visa/Master tölegi', 'TÖLENEN', '10130100040830', 5278, VM_TYPE, '2026-05-11T16:04:00Z', 'SUCCESS'),
|
||||||
|
buildPayment(1664, 'cd34e678-33cc-44dd-55ee-333333000003', 99438, '110526160730', 'billing_visa_master_username', 'Visa/Master tölegi', 'TÖLENEN', '10130100040830', 5277, VM_TYPE, '2026-05-11T16:03:00Z', 'SUCCESS'),
|
||||||
|
buildPayment(1663, 'de45f789-44dd-55ee-66ff-444444000004', 99438, '110526160715', 'billing_visa_master_username', 'Visa/Master tölegi', 'TÖLENEN', '10130100040830', 5276, VM_TYPE, '2026-05-11T16:01:00Z', 'SUCCESS'),
|
||||||
|
buildPayment(1662, 'ef56a890-55ee-66ff-77aa-555555000005', 99438, '110526155900', 'billing_visa_master_username', 'Visa/Master tölegi', 'TÖLENEN', '10130100040830', 5275, VM_TYPE, '2026-05-11T15:40:00Z', 'SUCCESS'),
|
||||||
|
buildPayment(1661, 'fa67b901-66ff-77aa-88bb-666666000006', 99438, '110526155830', 'billing_visa_master_username', 'Visa/Master tölegi', 'YATYRYLAN', '10130100040844', 5274, VM_TYPE, '2026-05-11T15:39:00Z'),
|
||||||
|
buildPayment(1660, 'ab78c012-77aa-88bb-99cc-777777000007', 99438, '110526155800', 'billing_visa_master_username', 'Visa/Master tölegi', 'TÖLENEN', '10130100040830', 5273, VM_TYPE, '2026-05-11T15:38:00Z', 'SUCCESS'),
|
||||||
|
buildPayment(1659, 'bc89d123-88bb-99cc-00dd-888888000008', 99438, '110526155730', 'billing_visa_master_username', 'Visa/Master tölegi', 'YATYRYLAN', '10130100040844', 5272, VM_TYPE, '2026-05-11T15:35:00Z'),
|
||||||
|
buildPayment(1658, 'cd90e234-99cc-00dd-11ee-999999000009', 99438, '110526152900', 'billing_visa_master_username', 'Visa/Master tölegi', 'TÖLENEN', '10130100040830', 5271, VM_TYPE, '2026-05-11T15:29:00Z', 'SUCCESS'),
|
||||||
|
buildPayment(1657, 'de01f345-00dd-11ee-22ff-000000000010', 99438, '110526103900', 'billing_visa_master_username', 'Visa/Master tölegi', 'GARAŞYLÝAR', '10130100040862', 5270, VM_TYPE, '2026-05-11T10:39:00Z'),
|
||||||
|
buildPayment(1656, 'ef12a456-11ee-22ff-33aa-111111000011', 99438, '110526103800', 'billing_visa_master_username', 'Visa/Master tölegi', 'GARAŞYLÝAR', '10130100040862', 5269, VM_TYPE, '2026-05-11T10:39:00Z'),
|
||||||
|
buildPayment(1655, 'fa23b567-22ff-33aa-44bb-222222000012', 99438, '110526103700', 'billing_visa_master_username', 'Visa/Master tölegi', 'GARAŞYLÝAR', '10130100040862', 5268, VM_TYPE, '2026-05-11T10:38:00Z'),
|
||||||
|
buildPayment(1654, 'ab34c678-33aa-44bb-55cc-333333000013', 99438, '110526103600', 'billing_visa_master_username', 'Visa/Master tölegi', 'GARAŞYLÝAR', '10130100040862', 5267, VM_TYPE, '2026-05-11T10:38:00Z'),
|
||||||
|
buildPayment(1653, 'bc45d789-44bb-55cc-66dd-444444000014', 99438, '110526085200', 'billing_visa_master_username', 'Visa/Master tölegi', 'GARAŞYLÝAR', '10130100040828', 5266, VM_TYPE, '2026-05-11T08:52:00Z'),
|
||||||
|
buildPayment(1652, 'cd56e890-55cc-66dd-77ee-555555000015', 99438, '060526142300', 'billing_visa_master_username', 'Visa/Master tölegi', 'GARAŞYLÝAR', '10130100040826', 5265, VM_TYPE, '2026-05-06T14:23:00Z'),
|
||||||
|
buildPayment(1651, 'de67f901-66dd-77ee-88ff-666666000016', 106345,'280426161300', 'billing_sber_username', 'Sber tölegi', 'GARAŞYLÝAR', '10130100040827', 5264, SBER_TYPE, '2026-04-28T16:13:00Z'),
|
||||||
|
buildPayment(1650, 'ef78a012-77ee-88ff-99aa-777777000017', 32, '250426130100', 'billing_username', 'Kart tölegi', 'GARAŞYLÝAR', '10130100004083', 5263, KART_TYPE, '2026-04-25T13:01:00Z'),
|
||||||
|
buildPayment(1649, 'fa89b123-88ff-99aa-00bb-888888000018', 32, '240426101900', 'billing_username', 'Kart tölegi', 'GARAŞYLÝAR', '10130100004083', 5262, KART_TYPE, '2026-04-24T10:19:00Z'),
|
||||||
|
buildPayment(1648, 'ab90c234-99aa-00bb-11cc-999999000019', 106344,'210426105900', 'billing_sber_username', 'Sber tölegi', 'TÖLENEN', '10130100040827', 5261, SBER_TYPE, '2026-04-21T10:59:00Z', 'SUCCESS'),
|
||||||
|
buildPayment(1647, 'bc01d345-00bb-11cc-22dd-000000000020', 106243,'200426153100', 'billing_sber_username', 'Sber tölegi', 'GARAŞYLÝAR', '10130100040833', 5260, SBER_TYPE, '2026-04-20T15:31:00Z'),
|
||||||
|
buildPayment(1646, 'cd12e456-11cc-22dd-33ee-111111000021', 99438, '170426111400', 'billing_visa_master_username', 'Visa/Master tölegi', 'TÖLENEN', '10130100040832', 5259, VM_TYPE, '2026-04-17T11:14:00Z', 'SUCCESS'),
|
||||||
|
buildPayment(1645, 'de23f567-22dd-33ee-44ff-222222000022', 99438, '170426103400', 'billing_visa_master_username', 'Visa/Master tölegi', 'GARAŞYLÝAR', '10130100040832', 5258, VM_TYPE, '2026-04-17T10:34:00Z'),
|
||||||
|
buildPayment(1644, 'ef34a678-33ee-44ff-55aa-333333000023', 99438, '160426175600', 'billing_visa_master_username', 'Visa/Master tölegi', 'GARAŞYLÝAR', '10130100040830', 5257, VM_TYPE, '2026-04-16T17:56:00Z'),
|
||||||
|
buildPayment(1643, 'fa45b789-44ff-55aa-66bb-444444000024', 99438, '150426155000', 'billing_visa_master_username', 'Visa/Master tölegi', 'TÖLENEN', '10130100040826', 5256, VM_TYPE, '2026-04-15T15:50:00Z', 'SUCCESS'),
|
||||||
|
]
|
||||||
|
|
||||||
|
// Total mock count is 1664 per screenshot — we serve paginated slices of the 25 above
|
||||||
|
const TOTAL_MOCK = 1664
|
||||||
|
|
||||||
|
const delay = (ms = 400) => new Promise<void>((res) => setTimeout(res, ms))
|
||||||
|
|
||||||
|
// ─── API Functions ────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
|
export async function fetchOnlinePayments(
|
||||||
|
params: OnlinePaymentListParams = {}
|
||||||
|
): Promise<OnlinePaymentListResponse> {
|
||||||
|
await delay()
|
||||||
|
const { page = 1, perPage = 25, search = '' } = params
|
||||||
|
|
||||||
|
let filtered = [...MOCK_PAYMENTS]
|
||||||
|
|
||||||
|
if (search.trim()) {
|
||||||
|
const q = search.toLowerCase()
|
||||||
|
filtered = filtered.filter(
|
||||||
|
(r) =>
|
||||||
|
String(r.amount).includes(q) ||
|
||||||
|
r.apiClient.toLowerCase().includes(q) ||
|
||||||
|
r.description.toLowerCase().includes(q)||
|
||||||
|
r.username.toLowerCase().includes(q) ||
|
||||||
|
r.status.toLowerCase().includes(q) ||
|
||||||
|
r.orderId.toLowerCase().includes(q)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
const total = search.trim() ? filtered.length : TOTAL_MOCK
|
||||||
|
const totalPages = Math.ceil(total / perPage)
|
||||||
|
const start = (page - 1) * perPage
|
||||||
|
const data = filtered.slice(start, start + perPage)
|
||||||
|
|
||||||
|
return { data, total, page, perPage, totalPages }
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function fetchOnlinePaymentById(id: number): Promise<OnlinePayment> {
|
||||||
|
await delay()
|
||||||
|
const item = MOCK_PAYMENTS.find((r) => r.id === id)
|
||||||
|
if (!item) throw new Error(`OnlinePayment with id ${id} not found`)
|
||||||
|
return { ...item }
|
||||||
|
}
|
||||||
|
|
||||||
|
// Callback trigger — mock only logs; in real impl would POST to backend
|
||||||
|
export async function triggerPaymentCallback(id: number): Promise<void> {
|
||||||
|
await delay(600)
|
||||||
|
const item = MOCK_PAYMENTS.find((r) => r.id === id)
|
||||||
|
if (!item) throw new Error(`OnlinePayment with id ${id} not found`)
|
||||||
|
// no-op in mock
|
||||||
|
}
|
||||||
@@ -0,0 +1,33 @@
|
|||||||
|
import {
|
||||||
|
StatusBadge,
|
||||||
|
type StatusBadgeVariant,
|
||||||
|
} from '@/components/ui/statusBadge'
|
||||||
|
import { AlertCircle, CheckCircle2, XCircle } from 'lucide-react'
|
||||||
|
import type { PaymentStatus } from '@/features/onlinePaymentHistory/api/onlinePaymentsHistoryApi'
|
||||||
|
|
||||||
|
const STATUS_CONFIG = {
|
||||||
|
GARAŞYLÝAR: {
|
||||||
|
label: 'Garaşylýar',
|
||||||
|
variant: 'warning' as StatusBadgeVariant,
|
||||||
|
icon: AlertCircle,
|
||||||
|
},
|
||||||
|
TÖLENEN: {
|
||||||
|
label: 'Tölenen',
|
||||||
|
variant: 'success' as StatusBadgeVariant,
|
||||||
|
icon: CheckCircle2,
|
||||||
|
},
|
||||||
|
YATYRYLAN: {
|
||||||
|
label: 'Ýatyrylan',
|
||||||
|
variant: 'error' as StatusBadgeVariant,
|
||||||
|
icon: XCircle,
|
||||||
|
},
|
||||||
|
} satisfies Record<
|
||||||
|
PaymentStatus,
|
||||||
|
{ label: string; variant: StatusBadgeVariant; icon: React.ElementType }
|
||||||
|
>
|
||||||
|
|
||||||
|
export function PaymentStatusBadge({ status }: { status: PaymentStatus }) {
|
||||||
|
const cfg = STATUS_CONFIG[status]
|
||||||
|
if (!cfg) return <span className="text-xs text-muted-foreground">{String(status)}</span>
|
||||||
|
return <StatusBadge label={cfg.label} variant={cfg.variant} icon={cfg.icon} />
|
||||||
|
}
|
||||||
@@ -0,0 +1,60 @@
|
|||||||
|
// features/onlinePaymentHistory/hooks/useOnlinePaymentHistory.ts
|
||||||
|
|
||||||
|
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query'
|
||||||
|
import { toast } from 'sonner'
|
||||||
|
import { useTranslation } from 'react-i18next'
|
||||||
|
import {
|
||||||
|
fetchOnlinePayments,
|
||||||
|
fetchOnlinePaymentById,
|
||||||
|
triggerPaymentCallback,
|
||||||
|
type OnlinePaymentListParams,
|
||||||
|
} from '../api/onlinePaymentsHistoryApi'
|
||||||
|
|
||||||
|
// ─── Query Keys ───────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
|
export const onlinePaymentKeys = {
|
||||||
|
all: ['onlinePayments'] as const,
|
||||||
|
lists: () => [...onlinePaymentKeys.all, 'list'] as const,
|
||||||
|
list: (params: OnlinePaymentListParams) =>
|
||||||
|
[...onlinePaymentKeys.lists(), params] as const,
|
||||||
|
detail: (id: number) =>
|
||||||
|
[...onlinePaymentKeys.all, 'detail', id] as const,
|
||||||
|
}
|
||||||
|
|
||||||
|
// ─── useGetOnlinePayments ─────────────────────────────────────────────────────
|
||||||
|
|
||||||
|
export function useGetOnlinePayments(params: OnlinePaymentListParams = {}) {
|
||||||
|
return useQuery({
|
||||||
|
queryKey: onlinePaymentKeys.list(params),
|
||||||
|
queryFn: () => fetchOnlinePayments(params),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// ─── useGetOnlinePaymentById ──────────────────────────────────────────────────
|
||||||
|
|
||||||
|
export function useGetOnlinePaymentById(id: number) {
|
||||||
|
return useQuery({
|
||||||
|
queryKey: onlinePaymentKeys.detail(id),
|
||||||
|
queryFn: () => fetchOnlinePaymentById(id),
|
||||||
|
enabled: !!id,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// ─── useTriggerPaymentCallback ────────────────────────────────────────────────
|
||||||
|
|
||||||
|
export function useTriggerPaymentCallback() {
|
||||||
|
const queryClient = useQueryClient()
|
||||||
|
const { t } = useTranslation()
|
||||||
|
|
||||||
|
return useMutation({
|
||||||
|
mutationFn: (id: number) => triggerPaymentCallback(id),
|
||||||
|
onSuccess: (_data, id) => {
|
||||||
|
queryClient.invalidateQueries({ queryKey: onlinePaymentKeys.detail(id) })
|
||||||
|
queryClient.invalidateQueries({ queryKey: onlinePaymentKeys.lists() })
|
||||||
|
toast.success(t('onlinePayments.toast.callbackTriggered', 'Callback ugradyldy'))
|
||||||
|
},
|
||||||
|
onError: () => {
|
||||||
|
toast.error(t('onlinePayments.toast.callbackError', 'Callback ugratmak başartmady'))
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
@@ -0,0 +1,134 @@
|
|||||||
|
// import {apiClient} from '@/lib/api/client'
|
||||||
|
|
||||||
|
// ─── Types ────────────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
|
export interface PermissionTranslation {
|
||||||
|
tk: string
|
||||||
|
ru: string
|
||||||
|
en: string
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface AuditLog {
|
||||||
|
id: number
|
||||||
|
action: string
|
||||||
|
by: string
|
||||||
|
target: string
|
||||||
|
status: string
|
||||||
|
date: string
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface Permission {
|
||||||
|
id: number
|
||||||
|
code: string
|
||||||
|
name: PermissionTranslation
|
||||||
|
guard_name: string
|
||||||
|
audit_logs?: AuditLog[]
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface PermissionPayload {
|
||||||
|
code: string
|
||||||
|
name: PermissionTranslation
|
||||||
|
guard_name: string
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface PermissionsListParams {
|
||||||
|
search?: string
|
||||||
|
page?: number
|
||||||
|
per_page?: number
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface PaginatedResponse<T> {
|
||||||
|
data: T[]
|
||||||
|
meta: {
|
||||||
|
current_page: number
|
||||||
|
last_page: number
|
||||||
|
per_page: number
|
||||||
|
total: number
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ─── Mock Data ────────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
|
const MOCK_PERMISSIONS: Permission[] = [
|
||||||
|
{ id: 1, code: 'users.view', guard_name: 'web', name: { tk: 'Ulanyjylary görmek', ru: 'Просмотр пользователей', en: 'View users' } },
|
||||||
|
{ id: 2, code: 'users.create', guard_name: 'web', name: { tk: 'Ulanyjy döretmek', ru: 'Создание пользователя', en: 'Create user' } },
|
||||||
|
{ id: 3, code: 'users.edit', guard_name: 'web', name: { tk: 'Ulanyjyny üýtgetmek', ru: 'Редактирование пользователя', en: 'Edit user' } },
|
||||||
|
{ id: 4, code: 'users.delete', guard_name: 'web', name: { tk: 'Ulanyjyny pozmak', ru: 'Удаление пользователя', en: 'Delete user' } },
|
||||||
|
{ id: 5, code: 'roles.view', guard_name: 'web', name: { tk: 'Rollary görmek', ru: 'Просмотр ролей', en: 'View roles' } },
|
||||||
|
{ id: 6, code: 'roles.create', guard_name: 'web', name: { tk: 'Rol döretmek', ru: 'Создание роли', en: 'Create role' } },
|
||||||
|
{ id: 7, code: 'roles.edit', guard_name: 'web', name: { tk: 'Roly üýtgetmek', ru: 'Редактирование роли', en: 'Edit role' } },
|
||||||
|
{ id: 8, code: 'roles.delete', guard_name: 'web', name: { tk: 'Roly pozmak', ru: 'Удаление роли', en: 'Delete role' } },
|
||||||
|
{ id: 9, code: 'permissions.view', guard_name: 'web', name: { tk: 'Rugsatlary görmek', ru: 'Просмотр разрешений', en: 'View permissions' } },
|
||||||
|
{ id: 10, code: 'permissions.edit', guard_name: 'web', name: { tk: 'Rugsady üýtgetmek', ru: 'Редактирование разрешения', en: 'Edit permission' } },
|
||||||
|
]
|
||||||
|
|
||||||
|
const delay = (ms = 500) => new Promise((res) => setTimeout(res, ms))
|
||||||
|
|
||||||
|
// ─── API functions ────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
|
export const permissionsApi = {
|
||||||
|
getAll: async (params?: PermissionsListParams): Promise<{ data: PaginatedResponse<Permission> }> => {
|
||||||
|
await delay()
|
||||||
|
const { search = '', page = 1, per_page = 25 } = params ?? {}
|
||||||
|
|
||||||
|
let filtered = [...MOCK_PERMISSIONS]
|
||||||
|
if (search) {
|
||||||
|
const s = search.toLowerCase()
|
||||||
|
filtered = filtered.filter(
|
||||||
|
(p) =>
|
||||||
|
p.code.toLowerCase().includes(s) ||
|
||||||
|
p.name.tk.toLowerCase().includes(s) ||
|
||||||
|
p.name.ru.toLowerCase().includes(s) ||
|
||||||
|
p.name.en.toLowerCase().includes(s)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
const total = filtered.length
|
||||||
|
const last_page = Math.ceil(total / per_page)
|
||||||
|
const start = (page - 1) * per_page
|
||||||
|
const data = filtered.slice(start, start + per_page)
|
||||||
|
|
||||||
|
return {
|
||||||
|
data: {
|
||||||
|
data,
|
||||||
|
meta: {
|
||||||
|
current_page: page,
|
||||||
|
last_page,
|
||||||
|
per_page,
|
||||||
|
total,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
getById: async (id: number): Promise<{ data: Permission }> => {
|
||||||
|
await delay()
|
||||||
|
const item = MOCK_PERMISSIONS.find((p) => p.id === id)
|
||||||
|
if (!item) throw new Error('Not found')
|
||||||
|
return { data: item }
|
||||||
|
},
|
||||||
|
|
||||||
|
create: async (payload: PermissionPayload): Promise<{ data: Permission }> => {
|
||||||
|
await delay()
|
||||||
|
const newItem: Permission = {
|
||||||
|
...payload,
|
||||||
|
id: Math.floor(Math.random() * 10000),
|
||||||
|
}
|
||||||
|
MOCK_PERMISSIONS.push(newItem)
|
||||||
|
return { data: newItem }
|
||||||
|
},
|
||||||
|
|
||||||
|
update: async (id: number, payload: PermissionPayload): Promise<{ data: Permission }> => {
|
||||||
|
await delay()
|
||||||
|
const index = MOCK_PERMISSIONS.findIndex((p) => p.id === id)
|
||||||
|
if (index === -1) throw new Error('Not found')
|
||||||
|
MOCK_PERMISSIONS[index] = { ...MOCK_PERMISSIONS[index], ...payload }
|
||||||
|
return { data: MOCK_PERMISSIONS[index] }
|
||||||
|
},
|
||||||
|
|
||||||
|
delete: async (id: number): Promise<void> => {
|
||||||
|
await delay()
|
||||||
|
const index = MOCK_PERMISSIONS.findIndex((p) => p.id === id)
|
||||||
|
if (index !== -1) MOCK_PERMISSIONS.splice(index, 1)
|
||||||
|
},
|
||||||
|
}
|
||||||
@@ -0,0 +1,202 @@
|
|||||||
|
import { useState } from 'react'
|
||||||
|
import { useNavigate } from 'react-router-dom'
|
||||||
|
import { useTranslation } from 'react-i18next'
|
||||||
|
import { FormInput } from '@/components/formInput'
|
||||||
|
import { Button } from '@/components/ui/button'
|
||||||
|
import { useCreatePermission, useUpdatePermission } from '../hooks/usePermissions'
|
||||||
|
import type { Permission, PermissionPayload } from '../api/permissionsApi'
|
||||||
|
|
||||||
|
// ─── Types ────────────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
|
interface PermissionFormProps {
|
||||||
|
mode: 'create' | 'edit'
|
||||||
|
initialData?: Permission
|
||||||
|
permissionId?: number
|
||||||
|
}
|
||||||
|
|
||||||
|
interface FormErrors {
|
||||||
|
code?: string
|
||||||
|
name_tk?: string
|
||||||
|
name_ru?: string
|
||||||
|
name_en?: string
|
||||||
|
guard_name?: string
|
||||||
|
}
|
||||||
|
|
||||||
|
type LangKey = 'tk' | 'ru' | 'en'
|
||||||
|
|
||||||
|
const LANG_TABS: { key: LangKey; label: string }[] = [
|
||||||
|
{ key: 'tk', label: 'Türkmen' },
|
||||||
|
{ key: 'ru', label: 'Русский' },
|
||||||
|
{ key: 'en', label: 'English' },
|
||||||
|
]
|
||||||
|
|
||||||
|
const GUARD_OPTIONS = [
|
||||||
|
{ value: 'web', label: 'web' },
|
||||||
|
{ value: 'api', label: 'api' },
|
||||||
|
{ value: 'sanctum', label: 'sanctum' },
|
||||||
|
]
|
||||||
|
|
||||||
|
// ─── PermissionForm ───────────────────────────────────────────────────────────
|
||||||
|
|
||||||
|
export function PermissionForm({ mode, initialData, permissionId }: PermissionFormProps) {
|
||||||
|
const { t } = useTranslation()
|
||||||
|
const navigate = useNavigate()
|
||||||
|
|
||||||
|
const createPermission = useCreatePermission()
|
||||||
|
const updatePermission = useUpdatePermission(permissionId ?? 0)
|
||||||
|
|
||||||
|
const isPending = createPermission.isPending || updatePermission.isPending
|
||||||
|
|
||||||
|
const [activeLang, setActiveLang] = useState<LangKey>('tk')
|
||||||
|
const [errors, setErrors] = useState<FormErrors>({})
|
||||||
|
|
||||||
|
const [form, setForm] = useState<PermissionPayload>({
|
||||||
|
code: initialData?.code ?? '',
|
||||||
|
guard_name: initialData?.guard_name ?? 'web',
|
||||||
|
name: {
|
||||||
|
tk: initialData?.name?.tk ?? '',
|
||||||
|
ru: initialData?.name?.ru ?? '',
|
||||||
|
en: initialData?.name?.en ?? '',
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
// ── Helpers ────────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
|
const setField = (field: keyof Omit<PermissionPayload, 'name'>, value: string) => {
|
||||||
|
setForm((prev) => ({ ...prev, [field]: value }))
|
||||||
|
setErrors((prev) => ({ ...prev, [field]: undefined }))
|
||||||
|
}
|
||||||
|
|
||||||
|
const setNameField = (lang: LangKey, value: string) => {
|
||||||
|
setForm((prev) => ({ ...prev, name: { ...prev.name, [lang]: value } }))
|
||||||
|
setErrors((prev) => ({ ...prev, [`name_${lang}`]: undefined }))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ── Validation ─────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
|
const validate = (): boolean => {
|
||||||
|
const newErrors: FormErrors = {}
|
||||||
|
|
||||||
|
if (!form.code.trim())
|
||||||
|
newErrors.code = t('permissions.validation.codeRequired', 'Kod hökman!')
|
||||||
|
if (!form.name.tk.trim())
|
||||||
|
newErrors.name_tk = t('permissions.validation.nameTkRequired', 'Türkmençe ady hökman!')
|
||||||
|
if (!form.guard_name.trim())
|
||||||
|
newErrors.guard_name = t('permissions.validation.guardRequired', 'Guard name hökman!')
|
||||||
|
|
||||||
|
setErrors(newErrors)
|
||||||
|
return Object.keys(newErrors).length === 0
|
||||||
|
}
|
||||||
|
|
||||||
|
// ── Submit ─────────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
|
const handleSubmit = () => {
|
||||||
|
if (!validate()) return
|
||||||
|
|
||||||
|
if (mode === 'create') {
|
||||||
|
createPermission.mutate(form, {
|
||||||
|
onSuccess: () => navigate('/settings/users/permissions'),
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
updatePermission.mutate(form, {
|
||||||
|
onSuccess: () => navigate('/settings/users/permissions'),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ── Render ─────────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="bg-card border border-border rounded-xl overflow-hidden">
|
||||||
|
|
||||||
|
{/* Code */}
|
||||||
|
<div className="grid grid-cols-[220px_1fr] items-start p-5 border-b border-border">
|
||||||
|
<span className="text-sm text-muted-foreground pt-2">
|
||||||
|
{t('permissions.fields.code', 'Kod')}
|
||||||
|
<span className="text-destructive ml-0.5">*</span>
|
||||||
|
</span>
|
||||||
|
<FormInput
|
||||||
|
type="text"
|
||||||
|
value={form.code}
|
||||||
|
onChange={(v) => setField('code', v)}
|
||||||
|
placeholder={t('permissions.fields.code', 'Kod')}
|
||||||
|
error={errors.code}
|
||||||
|
disabled={isPending}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Name (multilingual) */}
|
||||||
|
<div className="grid grid-cols-[220px_1fr] items-start p-5 border-b border-border">
|
||||||
|
<span className="text-sm text-muted-foreground pt-2">
|
||||||
|
{t('permissions.fields.name', 'Ady')}
|
||||||
|
<span className="text-destructive ml-0.5">*</span>
|
||||||
|
</span>
|
||||||
|
<div className="space-y-2">
|
||||||
|
<div className="flex gap-1 justify-end">
|
||||||
|
{LANG_TABS.map((tab) => (
|
||||||
|
<button
|
||||||
|
key={tab.key}
|
||||||
|
type="button"
|
||||||
|
onClick={() => setActiveLang(tab.key)}
|
||||||
|
className={`px-3 py-1 text-xs font-medium rounded-md transition-colors ${
|
||||||
|
activeLang === tab.key
|
||||||
|
? 'text-primary border-b-2 border-primary'
|
||||||
|
: 'text-muted-foreground hover:text-foreground'
|
||||||
|
}`}
|
||||||
|
>
|
||||||
|
{tab.label}
|
||||||
|
</button>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
<FormInput
|
||||||
|
type="text"
|
||||||
|
value={form.name[activeLang]}
|
||||||
|
onChange={(v) => setNameField(activeLang, v)}
|
||||||
|
placeholder={t('permissions.fields.name', 'Ady')}
|
||||||
|
error={errors[`name_${activeLang}` as keyof FormErrors]}
|
||||||
|
disabled={isPending}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Guard name */}
|
||||||
|
<div className="grid grid-cols-[220px_1fr] items-start p-5">
|
||||||
|
<span className="text-sm text-muted-foreground pt-2">
|
||||||
|
{t('permissions.fields.guardName', 'Guard name')}
|
||||||
|
<span className="text-destructive ml-0.5">*</span>
|
||||||
|
</span>
|
||||||
|
<FormInput
|
||||||
|
type="select"
|
||||||
|
value={form.guard_name}
|
||||||
|
onChange={(v) => setField('guard_name', v)}
|
||||||
|
options={GUARD_OPTIONS}
|
||||||
|
error={errors.guard_name}
|
||||||
|
disabled={isPending}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Actions */}
|
||||||
|
<div className="flex items-center justify-end gap-3 px-5 py-4 border-t border-border bg-muted/20">
|
||||||
|
<Button
|
||||||
|
type="button"
|
||||||
|
variant="outline"
|
||||||
|
onClick={() => navigate('/settings/users/permissions')}
|
||||||
|
disabled={isPending}
|
||||||
|
>
|
||||||
|
{t('common.cancel', 'Ýatyr')}
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
type="button"
|
||||||
|
onClick={handleSubmit}
|
||||||
|
disabled={isPending}
|
||||||
|
>
|
||||||
|
{isPending
|
||||||
|
? t('common.saving', 'Ýüklenýär...')
|
||||||
|
: mode === 'create'
|
||||||
|
? t('permissions.actions.create', 'Rugsat dörediň')
|
||||||
|
: t('permissions.actions.save', 'Ýatda sakla')}
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -0,0 +1,92 @@
|
|||||||
|
import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query'
|
||||||
|
import { toast } from 'sonner'
|
||||||
|
import { useTranslation } from 'react-i18next'
|
||||||
|
import {
|
||||||
|
permissionsApi,
|
||||||
|
type PermissionPayload,
|
||||||
|
type PermissionsListParams,
|
||||||
|
} from '../api/permissionsApi'
|
||||||
|
|
||||||
|
// ─── Query keys ───────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
|
export const permissionKeys = {
|
||||||
|
all: ['permissions'] as const,
|
||||||
|
list: (params: PermissionsListParams) => ['permissions', 'list', params] as const,
|
||||||
|
detail: (id: number) => ['permissions', 'detail', id] as const,
|
||||||
|
}
|
||||||
|
|
||||||
|
// ─── usePermissions (list) ────────────────────────────────────────────────────
|
||||||
|
|
||||||
|
export function usePermissions(params: PermissionsListParams) {
|
||||||
|
return useQuery({
|
||||||
|
queryKey: permissionKeys.list(params),
|
||||||
|
queryFn: () => permissionsApi.getAll(params).then((r) => r.data),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// ─── usePermission (single) ───────────────────────────────────────────────────
|
||||||
|
|
||||||
|
export function usePermission(id: number) {
|
||||||
|
return useQuery({
|
||||||
|
queryKey: permissionKeys.detail(id),
|
||||||
|
queryFn: () => permissionsApi.getById(id).then((r) => r.data),
|
||||||
|
enabled: !!id,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// ─── useCreatePermission ──────────────────────────────────────────────────────
|
||||||
|
|
||||||
|
export function useCreatePermission() {
|
||||||
|
const { t } = useTranslation()
|
||||||
|
const queryClient = useQueryClient()
|
||||||
|
|
||||||
|
return useMutation({
|
||||||
|
mutationFn: (payload: PermissionPayload) =>
|
||||||
|
permissionsApi.create(payload).then((r) => r.data),
|
||||||
|
onSuccess: () => {
|
||||||
|
queryClient.invalidateQueries({ queryKey: permissionKeys.all })
|
||||||
|
toast.success(t('permissions.toast.created', 'Rugsat üstünlikli döredildi!'))
|
||||||
|
},
|
||||||
|
onError: () => {
|
||||||
|
toast.error(t('permissions.toast.createError', 'Rugsat döretmekde ýalňyşlyk ýüze çykdy.'))
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// ─── useUpdatePermission ──────────────────────────────────────────────────────
|
||||||
|
|
||||||
|
export function useUpdatePermission(id: number) {
|
||||||
|
const { t } = useTranslation()
|
||||||
|
const queryClient = useQueryClient()
|
||||||
|
|
||||||
|
return useMutation({
|
||||||
|
mutationFn: (payload: PermissionPayload) =>
|
||||||
|
permissionsApi.update(id, payload).then((r) => r.data),
|
||||||
|
onSuccess: () => {
|
||||||
|
queryClient.invalidateQueries({ queryKey: permissionKeys.all })
|
||||||
|
queryClient.invalidateQueries({ queryKey: permissionKeys.detail(id) })
|
||||||
|
toast.success(t('permissions.toast.updated', 'Rugsat üstünlikli üýtgedildi!'))
|
||||||
|
},
|
||||||
|
onError: () => {
|
||||||
|
toast.error(t('permissions.toast.updateError', 'Rugsat üýtgetmekde ýalňyşlyk ýüze çykdy.'))
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// ─── useDeletePermission ──────────────────────────────────────────────────────
|
||||||
|
|
||||||
|
export function useDeletePermission() {
|
||||||
|
const { t } = useTranslation()
|
||||||
|
const queryClient = useQueryClient()
|
||||||
|
|
||||||
|
return useMutation({
|
||||||
|
mutationFn: (id: number) => permissionsApi.delete(id),
|
||||||
|
onSuccess: () => {
|
||||||
|
queryClient.invalidateQueries({ queryKey: permissionKeys.all })
|
||||||
|
toast.success(t('permissions.toast.deleted', 'Rugsat üstünlikli pozuldy!'))
|
||||||
|
},
|
||||||
|
onError: () => {
|
||||||
|
toast.error(t('permissions.toast.deleteError', 'Rugsat pozmakda ýalňyşlyk ýüze çykdy.'))
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
@@ -0,0 +1,118 @@
|
|||||||
|
// import {apiClient} from '@/lib/api/client'
|
||||||
|
|
||||||
|
// ─── Types ────────────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
|
export interface RoleTranslation {
|
||||||
|
tk: string
|
||||||
|
ru: string
|
||||||
|
en: string
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface Role {
|
||||||
|
id: number
|
||||||
|
code: string
|
||||||
|
name: RoleTranslation
|
||||||
|
guard_name: string
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface RolePayload {
|
||||||
|
code: string
|
||||||
|
name: RoleTranslation
|
||||||
|
guard_name: string
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface RolesListParams {
|
||||||
|
search?: string
|
||||||
|
page?: number
|
||||||
|
per_page?: number
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface PaginatedResponse<T> {
|
||||||
|
data: T[]
|
||||||
|
meta: {
|
||||||
|
current_page: number
|
||||||
|
last_page: number
|
||||||
|
per_page: number
|
||||||
|
total: number
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ─── Mock Data ────────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
|
const MOCK_ROLES: Role[] = [
|
||||||
|
{ id: 1, code: 'admin', guard_name: 'web', name: { tk: 'Administrator', ru: 'Администратор', en: 'Administrator' } },
|
||||||
|
{ id: 2, code: 'operator', guard_name: 'web', name: { tk: 'Operator', ru: 'Оператор', en: 'Operator' } },
|
||||||
|
{ id: 3, code: 'manager', guard_name: 'web', name: { tk: 'Menijer', ru: 'Менеджер', en: 'Manager' } },
|
||||||
|
{ id: 4, code: 'editor', guard_name: 'web', name: { tk: 'Redaktor', ru: 'Редактор', en: 'Editor' } },
|
||||||
|
]
|
||||||
|
|
||||||
|
const delay = (ms = 500) => new Promise((res) => setTimeout(res, ms))
|
||||||
|
|
||||||
|
// ─── API functions ────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
|
export const rolesApi = {
|
||||||
|
getAll: async (params?: RolesListParams): Promise<{ data: PaginatedResponse<Role> }> => {
|
||||||
|
await delay()
|
||||||
|
const { search = '', page = 1, per_page = 25 } = params ?? {}
|
||||||
|
|
||||||
|
let filtered = [...MOCK_ROLES]
|
||||||
|
if (search) {
|
||||||
|
const s = search.toLowerCase()
|
||||||
|
filtered = filtered.filter(
|
||||||
|
(r) =>
|
||||||
|
r.code.toLowerCase().includes(s) ||
|
||||||
|
r.name.tk.toLowerCase().includes(s) ||
|
||||||
|
r.name.ru.toLowerCase().includes(s) ||
|
||||||
|
r.name.en.toLowerCase().includes(s)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
const total = filtered.length
|
||||||
|
const last_page = Math.ceil(total / per_page)
|
||||||
|
const start = (page - 1) * per_page
|
||||||
|
const data = filtered.slice(start, start + per_page)
|
||||||
|
|
||||||
|
return {
|
||||||
|
data: {
|
||||||
|
data,
|
||||||
|
meta: {
|
||||||
|
current_page: page,
|
||||||
|
last_page,
|
||||||
|
per_page,
|
||||||
|
total,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
getById: async (id: number): Promise<{ data: Role }> => {
|
||||||
|
await delay()
|
||||||
|
const item = MOCK_ROLES.find((r) => r.id === id)
|
||||||
|
if (!item) throw new Error('Not found')
|
||||||
|
return { data: item }
|
||||||
|
},
|
||||||
|
|
||||||
|
create: async (payload: RolePayload): Promise<{ data: Role }> => {
|
||||||
|
await delay()
|
||||||
|
const newItem: Role = {
|
||||||
|
...payload,
|
||||||
|
id: Math.floor(Math.random() * 10000),
|
||||||
|
}
|
||||||
|
MOCK_ROLES.push(newItem)
|
||||||
|
return { data: newItem }
|
||||||
|
},
|
||||||
|
|
||||||
|
update: async (id: number, payload: RolePayload): Promise<{ data: Role }> => {
|
||||||
|
await delay()
|
||||||
|
const index = MOCK_ROLES.findIndex((r) => r.id === id)
|
||||||
|
if (index === -1) throw new Error('Not found')
|
||||||
|
MOCK_ROLES[index] = { ...MOCK_ROLES[index], ...payload }
|
||||||
|
return { data: MOCK_ROLES[index] }
|
||||||
|
},
|
||||||
|
|
||||||
|
delete: async (id: number): Promise<void> => {
|
||||||
|
await delay()
|
||||||
|
const index = MOCK_ROLES.findIndex((r) => r.id === id)
|
||||||
|
if (index !== -1) MOCK_ROLES.splice(index, 1)
|
||||||
|
},
|
||||||
|
}
|
||||||
@@ -0,0 +1,203 @@
|
|||||||
|
import { useState } from 'react'
|
||||||
|
import { useNavigate } from 'react-router-dom'
|
||||||
|
import { useTranslation } from 'react-i18next'
|
||||||
|
import { FormInput } from '@/components/formInput'
|
||||||
|
import { Button } from '@/components/ui/button'
|
||||||
|
import { useCreateRole, useUpdateRole } from '../hooks/useRoles'
|
||||||
|
import type { Role, RolePayload } from '../api/rolesApi'
|
||||||
|
|
||||||
|
// ─── Types ────────────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
|
interface RoleFormProps {
|
||||||
|
mode: 'create' | 'edit'
|
||||||
|
initialData?: Role
|
||||||
|
roleId?: number
|
||||||
|
}
|
||||||
|
|
||||||
|
interface FormErrors {
|
||||||
|
code?: string
|
||||||
|
name_tk?: string
|
||||||
|
name_ru?: string
|
||||||
|
name_en?: string
|
||||||
|
guard_name?: string
|
||||||
|
}
|
||||||
|
|
||||||
|
type LangKey = 'tk' | 'ru' | 'en'
|
||||||
|
|
||||||
|
const LANG_TABS: { key: LangKey; label: string }[] = [
|
||||||
|
{ key: 'tk', label: 'Türkmen' },
|
||||||
|
{ key: 'ru', label: 'Русский' },
|
||||||
|
{ key: 'en', label: 'English' },
|
||||||
|
]
|
||||||
|
|
||||||
|
const GUARD_OPTIONS = [
|
||||||
|
{ value: 'web', label: 'web' },
|
||||||
|
{ value: 'api', label: 'api' },
|
||||||
|
{ value: 'sanctum', label: 'sanctum' },
|
||||||
|
]
|
||||||
|
|
||||||
|
// ─── RoleForm ─────────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
|
export function RoleForm({ mode, initialData, roleId }: RoleFormProps) {
|
||||||
|
const { t } = useTranslation()
|
||||||
|
const navigate = useNavigate()
|
||||||
|
|
||||||
|
const createRole = useCreateRole()
|
||||||
|
const updateRole = useUpdateRole(roleId ?? 0)
|
||||||
|
|
||||||
|
const isPending = createRole.isPending || updateRole.isPending
|
||||||
|
|
||||||
|
const [activeLang, setActiveLang] = useState<LangKey>('tk')
|
||||||
|
const [errors, setErrors] = useState<FormErrors>({})
|
||||||
|
|
||||||
|
const [form, setForm] = useState<RolePayload>({
|
||||||
|
code: initialData?.code ?? '',
|
||||||
|
guard_name: initialData?.guard_name ?? 'web',
|
||||||
|
name: {
|
||||||
|
tk: initialData?.name?.tk ?? '',
|
||||||
|
ru: initialData?.name?.ru ?? '',
|
||||||
|
en: initialData?.name?.en ?? '',
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
// ── Helpers ────────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
|
const setField = (field: keyof Omit<RolePayload, 'name'>, value: string) => {
|
||||||
|
setForm((prev) => ({ ...prev, [field]: value }))
|
||||||
|
setErrors((prev) => ({ ...prev, [field]: undefined }))
|
||||||
|
}
|
||||||
|
|
||||||
|
const setNameField = (lang: LangKey, value: string) => {
|
||||||
|
setForm((prev) => ({ ...prev, name: { ...prev.name, [lang]: value } }))
|
||||||
|
setErrors((prev) => ({ ...prev, [`name_${lang}`]: undefined }))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ── Validation ─────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
|
const validate = (): boolean => {
|
||||||
|
const newErrors: FormErrors = {}
|
||||||
|
|
||||||
|
if (!form.code.trim())
|
||||||
|
newErrors.code = t('roles.validation.codeRequired', 'Kod hökman!')
|
||||||
|
if (!form.name.tk.trim())
|
||||||
|
newErrors.name_tk = t('roles.validation.nameTkRequired', 'Türkmençe ady hökman!')
|
||||||
|
if (!form.guard_name.trim())
|
||||||
|
newErrors.guard_name = t('roles.validation.guardRequired', 'Guard name hökman!')
|
||||||
|
|
||||||
|
setErrors(newErrors)
|
||||||
|
return Object.keys(newErrors).length === 0
|
||||||
|
}
|
||||||
|
|
||||||
|
// ── Submit ─────────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
|
const handleSubmit = () => {
|
||||||
|
if (!validate()) return
|
||||||
|
|
||||||
|
if (mode === 'create') {
|
||||||
|
createRole.mutate(form, {
|
||||||
|
onSuccess: () => navigate('/settings/users/roles'),
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
updateRole.mutate(form, {
|
||||||
|
onSuccess: () => navigate('/settings/users/roles'),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ── Render ─────────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="bg-card border border-border rounded-xl overflow-hidden">
|
||||||
|
|
||||||
|
{/* Code */}
|
||||||
|
<div className="grid grid-cols-[220px_1fr] items-start p-5 border-b border-border">
|
||||||
|
<span className="text-sm text-muted-foreground pt-2">
|
||||||
|
{t('roles.fields.code', 'Kod')}
|
||||||
|
<span className="text-destructive ml-0.5">*</span>
|
||||||
|
</span>
|
||||||
|
<FormInput
|
||||||
|
type="text"
|
||||||
|
value={form.code}
|
||||||
|
onChange={(v) => setField('code', v)}
|
||||||
|
placeholder={t('roles.fields.code', 'Kod')}
|
||||||
|
error={errors.code}
|
||||||
|
disabled={isPending}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Name (multilingual) */}
|
||||||
|
<div className="grid grid-cols-[220px_1fr] items-start p-5 border-b border-border">
|
||||||
|
<span className="text-sm text-muted-foreground pt-2">
|
||||||
|
{t('roles.fields.name', 'Ady')}
|
||||||
|
<span className="text-destructive ml-0.5">*</span>
|
||||||
|
</span>
|
||||||
|
<div className="space-y-2">
|
||||||
|
{/* Language tabs */}
|
||||||
|
<div className="flex gap-1 justify-end">
|
||||||
|
{LANG_TABS.map((tab) => (
|
||||||
|
<button
|
||||||
|
key={tab.key}
|
||||||
|
type="button"
|
||||||
|
onClick={() => setActiveLang(tab.key)}
|
||||||
|
className={`px-3 py-1 text-xs font-medium rounded-md transition-colors ${
|
||||||
|
activeLang === tab.key
|
||||||
|
? 'text-primary border-b-2 border-primary'
|
||||||
|
: 'text-muted-foreground hover:text-foreground'
|
||||||
|
}`}
|
||||||
|
>
|
||||||
|
{tab.label}
|
||||||
|
</button>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
<FormInput
|
||||||
|
type="text"
|
||||||
|
value={form.name[activeLang]}
|
||||||
|
onChange={(v) => setNameField(activeLang, v)}
|
||||||
|
placeholder={t('roles.fields.name', 'Ady')}
|
||||||
|
error={errors[`name_${activeLang}` as keyof FormErrors]}
|
||||||
|
disabled={isPending}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Guard name */}
|
||||||
|
<div className="grid grid-cols-[220px_1fr] items-start p-5">
|
||||||
|
<span className="text-sm text-muted-foreground pt-2">
|
||||||
|
{t('roles.fields.guardName', 'Guard name')}
|
||||||
|
<span className="text-destructive ml-0.5">*</span>
|
||||||
|
</span>
|
||||||
|
<FormInput
|
||||||
|
type="select"
|
||||||
|
value={form.guard_name}
|
||||||
|
onChange={(v) => setField('guard_name', v)}
|
||||||
|
options={GUARD_OPTIONS}
|
||||||
|
error={errors.guard_name}
|
||||||
|
disabled={isPending}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Actions */}
|
||||||
|
<div className="flex items-center justify-end gap-3 px-5 py-4 border-t border-border bg-muted/20">
|
||||||
|
<Button
|
||||||
|
type="button"
|
||||||
|
variant="outline"
|
||||||
|
onClick={() => navigate('/settings/users/roles')}
|
||||||
|
disabled={isPending}
|
||||||
|
>
|
||||||
|
{t('common.cancel', 'Ýatyr')}
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
type="button"
|
||||||
|
onClick={handleSubmit}
|
||||||
|
disabled={isPending}
|
||||||
|
>
|
||||||
|
{isPending
|
||||||
|
? t('common.saving', 'Ýüklenýär...')
|
||||||
|
: mode === 'create'
|
||||||
|
? t('roles.actions.create', 'Rol dörediň')
|
||||||
|
: t('roles.actions.save', 'Ýatda sakla')}
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -0,0 +1,86 @@
|
|||||||
|
import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query'
|
||||||
|
import { toast } from 'sonner'
|
||||||
|
import { useTranslation } from 'react-i18next'
|
||||||
|
import { rolesApi, type RolePayload, type RolesListParams } from '../api/rolesApi'
|
||||||
|
|
||||||
|
// ─── Query keys ───────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
|
export const roleKeys = {
|
||||||
|
all: ['roles'] as const,
|
||||||
|
list: (params: RolesListParams) => ['roles', 'list', params] as const,
|
||||||
|
detail: (id: number) => ['roles', 'detail', id] as const,
|
||||||
|
}
|
||||||
|
|
||||||
|
// ─── useRoles (list) ──────────────────────────────────────────────────────────
|
||||||
|
|
||||||
|
export function useRoles(params: RolesListParams) {
|
||||||
|
return useQuery({
|
||||||
|
queryKey: roleKeys.list(params),
|
||||||
|
queryFn: () => rolesApi.getAll(params).then((r) => r.data),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// ─── useRole (single) ─────────────────────────────────────────────────────────
|
||||||
|
|
||||||
|
export function useRole(id: number) {
|
||||||
|
return useQuery({
|
||||||
|
queryKey: roleKeys.detail(id),
|
||||||
|
queryFn: () => rolesApi.getById(id).then((r) => r.data),
|
||||||
|
enabled: !!id,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// ─── useCreateRole ────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
|
export function useCreateRole() {
|
||||||
|
const { t } = useTranslation()
|
||||||
|
const queryClient = useQueryClient()
|
||||||
|
|
||||||
|
return useMutation({
|
||||||
|
mutationFn: (payload: RolePayload) => rolesApi.create(payload).then((r) => r.data),
|
||||||
|
onSuccess: () => {
|
||||||
|
queryClient.invalidateQueries({ queryKey: roleKeys.all })
|
||||||
|
toast.success(t('roles.toast.created', 'Rol üstünlikli döredildi!'))
|
||||||
|
},
|
||||||
|
onError: () => {
|
||||||
|
toast.error(t('roles.toast.createError', 'Rol döretmekde ýalňyşlyk ýüze çykdy.'))
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// ─── useUpdateRole ────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
|
export function useUpdateRole(id: number) {
|
||||||
|
const { t } = useTranslation()
|
||||||
|
const queryClient = useQueryClient()
|
||||||
|
|
||||||
|
return useMutation({
|
||||||
|
mutationFn: (payload: RolePayload) => rolesApi.update(id, payload).then((r) => r.data),
|
||||||
|
onSuccess: () => {
|
||||||
|
queryClient.invalidateQueries({ queryKey: roleKeys.all })
|
||||||
|
queryClient.invalidateQueries({ queryKey: roleKeys.detail(id) })
|
||||||
|
toast.success(t('roles.toast.updated', 'Rol üstünlikli üýtgedildi!'))
|
||||||
|
},
|
||||||
|
onError: () => {
|
||||||
|
toast.error(t('roles.toast.updateError', 'Roly üýtgetmekde ýalňyşlyk ýüze çykdy.'))
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// ─── useDeleteRole ────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
|
export function useDeleteRole() {
|
||||||
|
const { t } = useTranslation()
|
||||||
|
const queryClient = useQueryClient()
|
||||||
|
|
||||||
|
return useMutation({
|
||||||
|
mutationFn: (id: number) => rolesApi.delete(id),
|
||||||
|
onSuccess: () => {
|
||||||
|
queryClient.invalidateQueries({ queryKey: roleKeys.all })
|
||||||
|
toast.success(t('roles.toast.deleted', 'Rol üstünlikli pozuldy!'))
|
||||||
|
},
|
||||||
|
onError: () => {
|
||||||
|
toast.error(t('roles.toast.deleteError', 'Roly pozmakda ýalňyşlyk ýüze çykdy.'))
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
@@ -0,0 +1,126 @@
|
|||||||
|
// features/visaMasterSettings/api/visaMasterSettingsApi.ts
|
||||||
|
|
||||||
|
export interface VisaMasterSetting {
|
||||||
|
id: number
|
||||||
|
kod: string
|
||||||
|
ady: string
|
||||||
|
yazgy: string
|
||||||
|
createdAt: string
|
||||||
|
updatedAt: string
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface VisaMasterSettingListParams {
|
||||||
|
page?: number
|
||||||
|
perPage?: number
|
||||||
|
search?: string
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface VisaMasterSettingListResponse {
|
||||||
|
data: VisaMasterSetting[]
|
||||||
|
total: number
|
||||||
|
page: number
|
||||||
|
perPage: number
|
||||||
|
totalPages: number
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface VisaMasterSettingPayload {
|
||||||
|
kod: string
|
||||||
|
ady: string
|
||||||
|
yazgy: string
|
||||||
|
}
|
||||||
|
|
||||||
|
// ─── Mock Store ───────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
|
let mockStore: VisaMasterSetting[] = [
|
||||||
|
{
|
||||||
|
id: 2,
|
||||||
|
kod: 'sber_payment_warning',
|
||||||
|
ady: 'Sber töleg duýduryş',
|
||||||
|
yazgy: 'Sber töleg duýduryş',
|
||||||
|
createdAt: '2026-03-10T08:00:00Z',
|
||||||
|
updatedAt: '2026-05-01T08:00:00Z',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 1,
|
||||||
|
kod: 'payment_warning_text',
|
||||||
|
ady: 'Visa/Master töleg duýduryş',
|
||||||
|
yazgy: 'Dogry töleg aýyny saýlamagyňyzy haýyş edýäris!!!!',
|
||||||
|
createdAt: '2026-01-05T09:00:00Z',
|
||||||
|
updatedAt: '2026-04-20T09:00:00Z',
|
||||||
|
},
|
||||||
|
]
|
||||||
|
|
||||||
|
let nextId = 3
|
||||||
|
|
||||||
|
const delay = (ms = 400) => new Promise<void>((res) => setTimeout(res, ms))
|
||||||
|
|
||||||
|
// ─── API Functions ────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
|
export async function fetchVisaMasterSettings(
|
||||||
|
params: VisaMasterSettingListParams = {}
|
||||||
|
): Promise<VisaMasterSettingListResponse> {
|
||||||
|
await delay()
|
||||||
|
const { page = 1, perPage = 25, search = '' } = params
|
||||||
|
|
||||||
|
let filtered = [...mockStore]
|
||||||
|
|
||||||
|
if (search.trim()) {
|
||||||
|
const q = search.toLowerCase()
|
||||||
|
filtered = filtered.filter(
|
||||||
|
(r) =>
|
||||||
|
r.kod.toLowerCase().includes(q) ||
|
||||||
|
r.ady.toLowerCase().includes(q) ||
|
||||||
|
r.yazgy.toLowerCase().includes(q) ||
|
||||||
|
String(r.id).includes(q)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
filtered.sort((a, b) => b.id - a.id)
|
||||||
|
|
||||||
|
const total = filtered.length
|
||||||
|
const totalPages = Math.ceil(total / perPage) || 1
|
||||||
|
const start = (page - 1) * perPage
|
||||||
|
const data = filtered.slice(start, start + perPage)
|
||||||
|
|
||||||
|
return { data, total, page, perPage, totalPages }
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function fetchVisaMasterSettingById(id: number): Promise<VisaMasterSetting> {
|
||||||
|
await delay()
|
||||||
|
const item = mockStore.find((r) => r.id === id)
|
||||||
|
if (!item) throw new Error(`VisaMasterSetting with id ${id} not found`)
|
||||||
|
return { ...item }
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function createVisaMasterSetting(
|
||||||
|
payload: VisaMasterSettingPayload
|
||||||
|
): Promise<VisaMasterSetting> {
|
||||||
|
await delay()
|
||||||
|
const now = new Date().toISOString()
|
||||||
|
const created: VisaMasterSetting = { id: nextId++, ...payload, createdAt: now, updatedAt: now }
|
||||||
|
mockStore = [created, ...mockStore]
|
||||||
|
return created
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function updateVisaMasterSetting(
|
||||||
|
id: number,
|
||||||
|
payload: VisaMasterSettingPayload
|
||||||
|
): Promise<VisaMasterSetting> {
|
||||||
|
await delay()
|
||||||
|
const idx = mockStore.findIndex((r) => r.id === id)
|
||||||
|
if (idx === -1) throw new Error(`VisaMasterSetting with id ${id} not found`)
|
||||||
|
const updated: VisaMasterSetting = {
|
||||||
|
...mockStore[idx],
|
||||||
|
...payload,
|
||||||
|
updatedAt: new Date().toISOString(),
|
||||||
|
}
|
||||||
|
mockStore = mockStore.map((r) => (r.id === id ? updated : r))
|
||||||
|
return updated
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function deleteVisaMasterSetting(id: number): Promise<void> {
|
||||||
|
await delay()
|
||||||
|
if (!mockStore.some((r) => r.id === id))
|
||||||
|
throw new Error(`VisaMasterSetting with id ${id} not found`)
|
||||||
|
mockStore = mockStore.filter((r) => r.id !== id)
|
||||||
|
}
|
||||||
@@ -0,0 +1,190 @@
|
|||||||
|
// features/visaMasterSettings/components/VisaMasterSettingForm.tsx
|
||||||
|
|
||||||
|
import { useEffect, useState } from 'react'
|
||||||
|
import { useNavigate } from 'react-router-dom'
|
||||||
|
import { useTranslation } from 'react-i18next'
|
||||||
|
import { FormInput } from '@/components/formInput'
|
||||||
|
import { Button } from '@/components/ui/button'
|
||||||
|
import { type VisaMasterSetting } from '../api/visaMasterSberSettingsApi'
|
||||||
|
import {
|
||||||
|
useCreateVisaMasterSetting,
|
||||||
|
useUpdateVisaMasterSetting,
|
||||||
|
} from '../hooks/useVisaMasterSettings'
|
||||||
|
|
||||||
|
// ─── Types ────────────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
|
interface FormState {
|
||||||
|
kod: string
|
||||||
|
ady: string
|
||||||
|
yazgy: string
|
||||||
|
}
|
||||||
|
|
||||||
|
interface FormErrors {
|
||||||
|
kod?: string
|
||||||
|
ady?: string
|
||||||
|
yazgy?: string
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface VisaMasterSettingFormProps {
|
||||||
|
mode: 'create' | 'edit'
|
||||||
|
initialData?: VisaMasterSetting
|
||||||
|
settingId?: number
|
||||||
|
}
|
||||||
|
|
||||||
|
// ─── Validation ───────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
|
function validate(
|
||||||
|
form: FormState,
|
||||||
|
t: (key: string, fallback: string) => string
|
||||||
|
): FormErrors {
|
||||||
|
const errors: FormErrors = {}
|
||||||
|
|
||||||
|
if (!form.kod.trim())
|
||||||
|
errors.kod = t('visaMasterSettings.errors.kodRequired', 'Kod giriziň')
|
||||||
|
|
||||||
|
if (!form.ady.trim())
|
||||||
|
errors.ady = t('visaMasterSettings.errors.adyRequired', 'Ady giriziň')
|
||||||
|
|
||||||
|
if (!form.yazgy.trim())
|
||||||
|
errors.yazgy = t('visaMasterSettings.errors.yazgyRequired', 'Yazgy giriziň')
|
||||||
|
|
||||||
|
return errors
|
||||||
|
}
|
||||||
|
|
||||||
|
// ─── VisaMasterSettingForm ────────────────────────────────────────────────────
|
||||||
|
|
||||||
|
export function VisaMasterSettingForm({
|
||||||
|
mode,
|
||||||
|
initialData,
|
||||||
|
settingId,
|
||||||
|
}: VisaMasterSettingFormProps) {
|
||||||
|
const { t } = useTranslation()
|
||||||
|
const navigate = useNavigate()
|
||||||
|
|
||||||
|
const [form, setForm] = useState<FormState>({
|
||||||
|
kod: initialData?.kod ?? '',
|
||||||
|
ady: initialData?.ady ?? '',
|
||||||
|
yazgy: initialData?.yazgy ?? '',
|
||||||
|
})
|
||||||
|
const [errors, setErrors] = useState<FormErrors>({})
|
||||||
|
|
||||||
|
const createMutation = useCreateVisaMasterSetting()
|
||||||
|
const updateMutation = useUpdateVisaMasterSetting(settingId ?? 0)
|
||||||
|
|
||||||
|
const isPending = createMutation.isPending || updateMutation.isPending
|
||||||
|
|
||||||
|
// Sync when initialData arrives (edit mode async fetch)
|
||||||
|
useEffect(() => {
|
||||||
|
if (mode === 'edit' && initialData) {
|
||||||
|
setForm({
|
||||||
|
kod: initialData.kod,
|
||||||
|
ady: initialData.ady,
|
||||||
|
yazgy: initialData.yazgy,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}, [mode, initialData])
|
||||||
|
|
||||||
|
const setField = (field: keyof FormState) => (val: string) => {
|
||||||
|
setForm((prev) => ({ ...prev, [field]: val }))
|
||||||
|
if (errors[field]) setErrors((prev) => ({ ...prev, [field]: undefined }))
|
||||||
|
}
|
||||||
|
|
||||||
|
const handleSubmit = async () => {
|
||||||
|
const validationErrors = validate(form, t)
|
||||||
|
if (Object.keys(validationErrors).length > 0) {
|
||||||
|
setErrors(validationErrors)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
const payload = { kod: form.kod.trim(), ady: form.ady.trim(), yazgy: form.yazgy.trim() }
|
||||||
|
|
||||||
|
if (mode === 'create') {
|
||||||
|
await createMutation.mutateAsync(payload)
|
||||||
|
navigate('/resources/visa-master-settings')
|
||||||
|
} else {
|
||||||
|
await updateMutation.mutateAsync(payload)
|
||||||
|
navigate('/resources/visa-master-settings')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const handleCancel = () => navigate('/resources/visa-master-settings')
|
||||||
|
|
||||||
|
// ─── Render ───────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="space-y-0">
|
||||||
|
{/* Kod */}
|
||||||
|
<div className="grid grid-cols-[220px_1fr] items-start py-4 px-6 border-b border-border">
|
||||||
|
<label className="text-sm text-muted-foreground pt-1.5">
|
||||||
|
{t('visaMasterSettings.fields.kod', 'Kod')}
|
||||||
|
<span className="text-destructive ml-0.5">*</span>
|
||||||
|
</label>
|
||||||
|
<FormInput
|
||||||
|
type="text"
|
||||||
|
value={form.kod}
|
||||||
|
onChange={setField('kod')}
|
||||||
|
placeholder={t('visaMasterSettings.fields.kod', 'Kod')}
|
||||||
|
error={errors.kod}
|
||||||
|
disabled={isPending}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Ady */}
|
||||||
|
<div className="grid grid-cols-[220px_1fr] items-start py-4 px-6 border-b border-border">
|
||||||
|
<label className="text-sm text-muted-foreground pt-1.5">
|
||||||
|
{t('visaMasterSettings.fields.ady', 'Ady')}
|
||||||
|
<span className="text-destructive ml-0.5">*</span>
|
||||||
|
</label>
|
||||||
|
<FormInput
|
||||||
|
type="text"
|
||||||
|
value={form.ady}
|
||||||
|
onChange={setField('ady')}
|
||||||
|
placeholder={t('visaMasterSettings.fields.ady', 'Ady')}
|
||||||
|
error={errors.ady}
|
||||||
|
disabled={isPending}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Yazgy */}
|
||||||
|
<div className="grid grid-cols-[220px_1fr] items-start py-4 px-6">
|
||||||
|
<label className="text-sm text-muted-foreground pt-1.5">
|
||||||
|
{t('visaMasterSettings.fields.yazgy', 'Yazgy')}
|
||||||
|
<span className="text-destructive ml-0.5">*</span>
|
||||||
|
</label>
|
||||||
|
<FormInput
|
||||||
|
type="textarea"
|
||||||
|
value={form.yazgy}
|
||||||
|
onChange={setField('yazgy')}
|
||||||
|
placeholder={t('visaMasterSettings.fields.yazgy', 'Yazgy')}
|
||||||
|
error={errors.yazgy}
|
||||||
|
disabled={isPending}
|
||||||
|
rows={3}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Footer */}
|
||||||
|
<div className="flex items-center justify-end gap-3 px-6 py-4 border-t border-border">
|
||||||
|
<Button
|
||||||
|
type="button"
|
||||||
|
variant="ghost"
|
||||||
|
onClick={handleCancel}
|
||||||
|
disabled={isPending}
|
||||||
|
>
|
||||||
|
{t('common.cancel', 'Ýatyr')}
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
type="button"
|
||||||
|
onClick={handleSubmit}
|
||||||
|
disabled={isPending}
|
||||||
|
className="bg-primary text-primary-foreground hover:bg-primary/90"
|
||||||
|
>
|
||||||
|
{isPending
|
||||||
|
? t('common.saving', 'Saklanýar...')
|
||||||
|
: mode === 'create'
|
||||||
|
? t('visaMasterSettings.actions.create', 'Visa/Master, Sber sazlamalar dörediň')
|
||||||
|
: t('visaMasterSettings.actions.update', 'Ýatda sakla')}
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -0,0 +1,99 @@
|
|||||||
|
// features/visaMasterSettings/hooks/useVisaMasterSettings.ts
|
||||||
|
|
||||||
|
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query'
|
||||||
|
import { toast } from 'sonner'
|
||||||
|
import { useTranslation } from 'react-i18next'
|
||||||
|
import {
|
||||||
|
fetchVisaMasterSettings,
|
||||||
|
fetchVisaMasterSettingById,
|
||||||
|
createVisaMasterSetting,
|
||||||
|
updateVisaMasterSetting,
|
||||||
|
deleteVisaMasterSetting,
|
||||||
|
type VisaMasterSettingListParams,
|
||||||
|
type VisaMasterSettingPayload,
|
||||||
|
} from '../api/visaMasterSberSettingsApi'
|
||||||
|
|
||||||
|
// ─── Query Keys ───────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
|
export const visaMasterSettingKeys = {
|
||||||
|
all: ['visaMasterSettings'] as const,
|
||||||
|
lists: () => [...visaMasterSettingKeys.all, 'list'] as const,
|
||||||
|
list: (params: VisaMasterSettingListParams) =>
|
||||||
|
[...visaMasterSettingKeys.lists(), params] as const,
|
||||||
|
detail: (id: number) =>
|
||||||
|
[...visaMasterSettingKeys.all, 'detail', id] as const,
|
||||||
|
}
|
||||||
|
|
||||||
|
// ─── useGetVisaMasterSettings ─────────────────────────────────────────────────
|
||||||
|
|
||||||
|
export function useGetVisaMasterSettings(params: VisaMasterSettingListParams = {}) {
|
||||||
|
return useQuery({
|
||||||
|
queryKey: visaMasterSettingKeys.list(params),
|
||||||
|
queryFn: () => fetchVisaMasterSettings(params),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// ─── useGetVisaMasterSettingById ──────────────────────────────────────────────
|
||||||
|
|
||||||
|
export function useGetVisaMasterSettingById(id: number) {
|
||||||
|
return useQuery({
|
||||||
|
queryKey: visaMasterSettingKeys.detail(id),
|
||||||
|
queryFn: () => fetchVisaMasterSettingById(id),
|
||||||
|
enabled: !!id,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// ─── useCreateVisaMasterSetting ───────────────────────────────────────────────
|
||||||
|
|
||||||
|
export function useCreateVisaMasterSetting() {
|
||||||
|
const queryClient = useQueryClient()
|
||||||
|
const { t } = useTranslation()
|
||||||
|
|
||||||
|
return useMutation({
|
||||||
|
mutationFn: (payload: VisaMasterSettingPayload) => createVisaMasterSetting(payload),
|
||||||
|
onSuccess: () => {
|
||||||
|
queryClient.invalidateQueries({ queryKey: visaMasterSettingKeys.lists() })
|
||||||
|
toast.success(t('visaMasterSettings.toast.created', 'Sazlama döredildi'))
|
||||||
|
},
|
||||||
|
onError: () => {
|
||||||
|
toast.error(t('visaMasterSettings.toast.createError', 'Döretmek başartmady'))
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// ─── useUpdateVisaMasterSetting ───────────────────────────────────────────────
|
||||||
|
|
||||||
|
export function useUpdateVisaMasterSetting(id: number) {
|
||||||
|
const queryClient = useQueryClient()
|
||||||
|
const { t } = useTranslation()
|
||||||
|
|
||||||
|
return useMutation({
|
||||||
|
mutationFn: (payload: VisaMasterSettingPayload) => updateVisaMasterSetting(id, payload),
|
||||||
|
onSuccess: () => {
|
||||||
|
queryClient.invalidateQueries({ queryKey: visaMasterSettingKeys.lists() })
|
||||||
|
queryClient.invalidateQueries({ queryKey: visaMasterSettingKeys.detail(id) })
|
||||||
|
toast.success(t('visaMasterSettings.toast.updated', 'Sazlama üýtgedildi'))
|
||||||
|
},
|
||||||
|
onError: () => {
|
||||||
|
toast.error(t('visaMasterSettings.toast.updateError', 'Üýtgetmek başartmady'))
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// ─── useDeleteVisaMasterSetting ───────────────────────────────────────────────
|
||||||
|
|
||||||
|
export function useDeleteVisaMasterSetting() {
|
||||||
|
const queryClient = useQueryClient()
|
||||||
|
const { t } = useTranslation()
|
||||||
|
|
||||||
|
return useMutation({
|
||||||
|
mutationFn: (id: number) => deleteVisaMasterSetting(id),
|
||||||
|
onSuccess: () => {
|
||||||
|
queryClient.invalidateQueries({ queryKey: visaMasterSettingKeys.lists() })
|
||||||
|
toast.success(t('visaMasterSettings.toast.deleted', 'Sazlama pozuldy'))
|
||||||
|
},
|
||||||
|
onError: () => {
|
||||||
|
toast.error(t('visaMasterSettings.toast.deleteError', 'Pozmak başartmady'))
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
@@ -338,20 +338,20 @@ function AppSidebar() {
|
|||||||
items: [
|
items: [
|
||||||
{
|
{
|
||||||
title: t("Currency rates", "Walýuta kurslary"),
|
title: t("Currency rates", "Walýuta kurslary"),
|
||||||
url: "/currencies/rates",
|
url: "/currency-rates",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title: t(
|
title: t(
|
||||||
"Visa/Master, Sber Settings",
|
"Visa/Master, Sber Settings",
|
||||||
"Visa/Master, Sber sazlamalary",
|
"Visa/Master, Sber sazlamalary",
|
||||||
),
|
),
|
||||||
url: "/currencies/settings",
|
url: "/visa-master-sber-settings",
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title: t("Online payment history", "Onlaýn töleg taryhy"),
|
title: t("Online payment history", "Onlaýn töleg taryhy"),
|
||||||
url: "/online-payments",
|
url: "/online-payments-history",
|
||||||
icon: CreditCard,
|
icon: CreditCard,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
|||||||
@@ -0,0 +1,208 @@
|
|||||||
|
// pages/CurrencyRatesPage.tsx
|
||||||
|
|
||||||
|
import { useState } from 'react'
|
||||||
|
import { useNavigate } from 'react-router-dom'
|
||||||
|
import { useTranslation } from 'react-i18next'
|
||||||
|
import { Eye, Pencil, Trash2 } from 'lucide-react'
|
||||||
|
import { DataTable, type ColumnDef } from '@/components/dataTable'
|
||||||
|
import { DataTableToolbar } from '@/components/dataTableToolbar'
|
||||||
|
import { Button } from '@/components/ui/button'
|
||||||
|
import {
|
||||||
|
AlertDialog,
|
||||||
|
AlertDialogAction,
|
||||||
|
AlertDialogCancel,
|
||||||
|
AlertDialogContent,
|
||||||
|
AlertDialogDescription,
|
||||||
|
AlertDialogFooter,
|
||||||
|
AlertDialogHeader,
|
||||||
|
AlertDialogTitle,
|
||||||
|
} from '@/components/ui/alert-dialog'
|
||||||
|
import { useGetCurrencyRates, useDeleteCurrencyRate } from '@/features/currencyRates/hooks/useCurrencyRates'
|
||||||
|
import type { CurrencyRate } from '@/features/currencyRates/api/currencyRatesApi'
|
||||||
|
|
||||||
|
// ─── Column visibility defaults ───────────────────────────────────────────────
|
||||||
|
|
||||||
|
const DEFAULT_VISIBILITY = { id: true, currencyFrom: true, currencyTo: true, value: true }
|
||||||
|
const DEFAULT_ORDER = ['id', 'currencyFrom', 'currencyTo', 'value', 'actions']
|
||||||
|
|
||||||
|
// ─── CurrencyRatesPage ────────────────────────────────────────────────────────
|
||||||
|
|
||||||
|
export default function CurrencyRatesPage() {
|
||||||
|
const { t } = useTranslation()
|
||||||
|
const navigate = useNavigate()
|
||||||
|
|
||||||
|
const [page, setPage] = useState(1)
|
||||||
|
const [perPage] = useState(25)
|
||||||
|
const [search, setSearch] = useState('')
|
||||||
|
const [columnVisibility, setColumnVisibility] = useState<Record<string, boolean>>(DEFAULT_VISIBILITY)
|
||||||
|
const [columnOrder, setColumnOrder] = useState(DEFAULT_ORDER)
|
||||||
|
const [deleteId, setDeleteId] = useState<number | null>(null)
|
||||||
|
|
||||||
|
const { data, isLoading } = useGetCurrencyRates({ page, perPage, search })
|
||||||
|
const deleteMutation = useDeleteCurrencyRate()
|
||||||
|
|
||||||
|
const handleDeleteConfirm = async () => {
|
||||||
|
if (deleteId === null) return
|
||||||
|
await deleteMutation.mutateAsync(deleteId)
|
||||||
|
setDeleteId(null)
|
||||||
|
}
|
||||||
|
|
||||||
|
const handleSearchChange = (val: string) => {
|
||||||
|
setSearch(val)
|
||||||
|
setPage(1)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ─── Columns ──────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
|
const columns: ColumnDef<CurrencyRate>[] = [
|
||||||
|
{
|
||||||
|
accessorKey: 'id',
|
||||||
|
header: 'ID',
|
||||||
|
cell: ({ row }) => (
|
||||||
|
<button
|
||||||
|
className="text-primary font-semibold hover:underline"
|
||||||
|
onClick={() => navigate(`/resources/currency-rates/${row.original.id}`)}
|
||||||
|
>
|
||||||
|
{row.original.id}
|
||||||
|
</button>
|
||||||
|
),
|
||||||
|
size: 80,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
accessorKey: 'currencyFrom',
|
||||||
|
header: t('currencyRates.columns.currencyFrom', 'CURRENCY FROM'),
|
||||||
|
cell: ({ row }) => (
|
||||||
|
<span className="font-medium text-foreground">{row.original.currencyFrom}</span>
|
||||||
|
),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
accessorKey: 'currencyTo',
|
||||||
|
header: t('currencyRates.columns.currencyTo', 'CURRENCY TO'),
|
||||||
|
cell: ({ row }) => (
|
||||||
|
<span className="font-medium text-foreground">{row.original.currencyTo}</span>
|
||||||
|
),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
accessorKey: 'value',
|
||||||
|
header: t('currencyRates.columns.value', 'VALUE'),
|
||||||
|
cell: ({ row }) => (
|
||||||
|
<span className="text-foreground tabular-nums">{row.original.value}</span>
|
||||||
|
),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 'actions',
|
||||||
|
header: '',
|
||||||
|
enableSorting: false,
|
||||||
|
enableHiding: false,
|
||||||
|
cell: ({ row }) => (
|
||||||
|
<div className="flex items-center justify-end gap-1">
|
||||||
|
<Button
|
||||||
|
variant="ghost"
|
||||||
|
size="icon"
|
||||||
|
className="h-8 w-8 text-muted-foreground hover:text-foreground"
|
||||||
|
onClick={() => navigate(`/currency-rates/${row.original.id}`)}
|
||||||
|
title={t('common.view', 'Görmek')}
|
||||||
|
>
|
||||||
|
<Eye size={15} />
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
variant="ghost"
|
||||||
|
size="icon"
|
||||||
|
className="h-8 w-8 text-muted-foreground hover:text-foreground"
|
||||||
|
onClick={() => navigate(`/currency-rates/${row.original.id}/edit`)}
|
||||||
|
title={t('common.edit', 'Üýtgetmek')}
|
||||||
|
>
|
||||||
|
<Pencil size={15} />
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
variant="ghost"
|
||||||
|
size="icon"
|
||||||
|
className="h-8 w-8 text-muted-foreground hover:text-destructive"
|
||||||
|
onClick={() => setDeleteId(row.original.id)}
|
||||||
|
title={t('common.delete', 'Pozmak')}
|
||||||
|
>
|
||||||
|
<Trash2 size={15} />
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
),
|
||||||
|
size: 120,
|
||||||
|
},
|
||||||
|
]
|
||||||
|
|
||||||
|
const columnMeta = columns
|
||||||
|
.filter((c) => 'accessorKey' in c && c.accessorKey)
|
||||||
|
.map((c) => ({
|
||||||
|
id: String(('accessorKey' in c ? c.accessorKey : c.id) ?? ''),
|
||||||
|
label: typeof c.header === 'string' ? c.header : String(('accessorKey' in c ? c.accessorKey : '') ?? ''),
|
||||||
|
}))
|
||||||
|
|
||||||
|
// ─── Render ───────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="p-6">
|
||||||
|
|
||||||
|
|
||||||
|
<h1 className="text-2xl font-semibold text-foreground mb-5">
|
||||||
|
{t('currencyRates.title', 'Walýuta kursy')}
|
||||||
|
</h1>
|
||||||
|
|
||||||
|
<DataTableToolbar
|
||||||
|
searchValue={search}
|
||||||
|
onSearchChange={handleSearchChange}
|
||||||
|
searchPlaceholder={t('common.search', 'Gözlemek')}
|
||||||
|
columns={columnMeta}
|
||||||
|
columnVisibility={columnVisibility}
|
||||||
|
onColumnVisibilityChange={setColumnVisibility}
|
||||||
|
columnOrder={columnOrder}
|
||||||
|
onColumnOrderChange={setColumnOrder}
|
||||||
|
actionLabel={t('currencyRates.actions.create', 'Walýuta kursy dörediň')}
|
||||||
|
onAction={() => navigate('/currency-rates/create')}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<DataTable
|
||||||
|
columns={columns}
|
||||||
|
data={data?.data ?? []}
|
||||||
|
isLoading={isLoading}
|
||||||
|
columnVisibility={columnVisibility}
|
||||||
|
onColumnVisibilityChange={setColumnVisibility}
|
||||||
|
columnOrder={columnOrder}
|
||||||
|
onColumnOrderChange={setColumnOrder}
|
||||||
|
enableRowSelection
|
||||||
|
getRowId={(row) => String(row.id)}
|
||||||
|
currentPage={page}
|
||||||
|
totalPages={data?.totalPages ?? 1}
|
||||||
|
totalCount={data?.total ?? 0}
|
||||||
|
onPageChange={setPage}
|
||||||
|
/>
|
||||||
|
|
||||||
|
{/* Delete Confirmation Dialog */}
|
||||||
|
<AlertDialog open={deleteId !== null} onOpenChange={(open) => { if (!open) setDeleteId(null) }}>
|
||||||
|
<AlertDialogContent>
|
||||||
|
<AlertDialogHeader>
|
||||||
|
<AlertDialogTitle>
|
||||||
|
{t('currencyRates.deleteDialog.title', 'Pozmak isleýärsiňizmi?')}
|
||||||
|
</AlertDialogTitle>
|
||||||
|
<AlertDialogDescription>
|
||||||
|
{t(
|
||||||
|
'currencyRates.deleteDialog.description',
|
||||||
|
'Bu amal yzyna gaýtarylyp bilinmez. Walýuta kursy hemişelik pozular.'
|
||||||
|
)}
|
||||||
|
</AlertDialogDescription>
|
||||||
|
</AlertDialogHeader>
|
||||||
|
<AlertDialogFooter>
|
||||||
|
<AlertDialogCancel>{t('common.cancel', 'Ýatyr')}</AlertDialogCancel>
|
||||||
|
<AlertDialogAction
|
||||||
|
onClick={handleDeleteConfirm}
|
||||||
|
disabled={deleteMutation.isPending}
|
||||||
|
className="bg-destructive text-destructive-foreground hover:bg-destructive/90"
|
||||||
|
>
|
||||||
|
{deleteMutation.isPending
|
||||||
|
? t('common.deleting', 'Pozulýar...')
|
||||||
|
: t('common.delete', 'Pozmak')}
|
||||||
|
</AlertDialogAction>
|
||||||
|
</AlertDialogFooter>
|
||||||
|
</AlertDialogContent>
|
||||||
|
</AlertDialog>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
// pages/CurrencyRateCreatePage.tsx
|
||||||
|
|
||||||
|
import { useTranslation } from 'react-i18next'
|
||||||
|
import { CurrencyRateForm } from '@/features/currencyRates/components/currencyRatesForm'
|
||||||
|
|
||||||
|
// ─── CurrencyRateCreatePage ───────────────────────────────────────────────────
|
||||||
|
|
||||||
|
export default function CurrencyRateCreatePage() {
|
||||||
|
const { t } = useTranslation()
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="p-6">
|
||||||
|
|
||||||
|
<h1 className="text-2xl font-semibold text-foreground mb-6">
|
||||||
|
{t('currencyRates.actions.create', 'Walýuta kursy dörediň')}
|
||||||
|
</h1>
|
||||||
|
|
||||||
|
<div className="bg-card border border-border rounded-xl overflow-hidden">
|
||||||
|
<CurrencyRateForm mode="create" />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -0,0 +1,57 @@
|
|||||||
|
// pages/CurrencyRateEditPage.tsx
|
||||||
|
|
||||||
|
import { useParams } from 'react-router-dom'
|
||||||
|
import { useTranslation } from 'react-i18next'
|
||||||
|
import { CurrencyRateForm } from '@/features/currencyRates/components/currencyRatesForm'
|
||||||
|
import { useGetCurrencyRateById } from '@/features/currencyRates/hooks/useCurrencyRates'
|
||||||
|
|
||||||
|
// ─── CurrencyRateEditPage ─────────────────────────────────────────────────────
|
||||||
|
|
||||||
|
export default function CurrencyRateEditPage() {
|
||||||
|
const { id } = useParams<{ id: string }>()
|
||||||
|
const numericId = Number(id)
|
||||||
|
const { t } = useTranslation()
|
||||||
|
|
||||||
|
const { data: rate, isLoading } = useGetCurrencyRateById(numericId)
|
||||||
|
|
||||||
|
// ─── Loading skeleton ──────────────────────────────────────────────────────
|
||||||
|
|
||||||
|
if (isLoading) {
|
||||||
|
return (
|
||||||
|
<div className="p-6 space-y-4">
|
||||||
|
<div className="h-6 w-64 bg-muted rounded animate-pulse" />
|
||||||
|
<div className="h-48 bg-muted rounded-xl animate-pulse" />
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!rate) {
|
||||||
|
return (
|
||||||
|
<div className="p-6">
|
||||||
|
<p className="text-muted-foreground">
|
||||||
|
{t('currencyRates.notFound', 'Walýuta kursy tapylmady')}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ─── Render ───────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="p-6">
|
||||||
|
|
||||||
|
|
||||||
|
<h1 className="text-2xl font-semibold text-foreground mb-6">
|
||||||
|
{t('currencyRates.detail.editTitle', 'Walýuta kursyny üýtgetmek')}: {rate.id}
|
||||||
|
</h1>
|
||||||
|
|
||||||
|
<div className="bg-card border border-border rounded-xl overflow-hidden">
|
||||||
|
<CurrencyRateForm
|
||||||
|
mode="edit"
|
||||||
|
initialData={rate}
|
||||||
|
rateId={numericId}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -0,0 +1,137 @@
|
|||||||
|
// pages/CurrencyRateDetailPage.tsx
|
||||||
|
|
||||||
|
import { useNavigate, useParams } from 'react-router-dom'
|
||||||
|
import { useTranslation } from 'react-i18next'
|
||||||
|
import { Pencil, Trash2 } from 'lucide-react'
|
||||||
|
import { useState } from 'react'
|
||||||
|
import {
|
||||||
|
AlertDialog,
|
||||||
|
AlertDialogAction,
|
||||||
|
AlertDialogCancel,
|
||||||
|
AlertDialogContent,
|
||||||
|
AlertDialogDescription,
|
||||||
|
AlertDialogFooter,
|
||||||
|
AlertDialogHeader,
|
||||||
|
AlertDialogTitle,
|
||||||
|
} from '@/components/ui/alert-dialog'
|
||||||
|
import { Button } from '@/components/ui/button'
|
||||||
|
import { Section, InfoRow } from '@/components/viewPageComponents'
|
||||||
|
import { useGetCurrencyRateById, useDeleteCurrencyRate } from '@/features/currencyRates/hooks/useCurrencyRates'
|
||||||
|
|
||||||
|
// ─── CurrencyRateDetailPage ───────────────────────────────────────────────────
|
||||||
|
|
||||||
|
export default function CurrencyRateDetailPage() {
|
||||||
|
const { id } = useParams<{ id: string }>()
|
||||||
|
const numericId = Number(id)
|
||||||
|
const { t } = useTranslation()
|
||||||
|
const navigate = useNavigate()
|
||||||
|
|
||||||
|
const [deleteOpen, setDeleteOpen] = useState(false)
|
||||||
|
|
||||||
|
const { data: rate, isLoading } = useGetCurrencyRateById(numericId)
|
||||||
|
const deleteMutation = useDeleteCurrencyRate()
|
||||||
|
|
||||||
|
const handleDeleteConfirm = async () => {
|
||||||
|
await deleteMutation.mutateAsync(numericId)
|
||||||
|
navigate('/resources/currency-rates')
|
||||||
|
}
|
||||||
|
|
||||||
|
// ─── Loading skeleton ──────────────────────────────────────────────────────
|
||||||
|
|
||||||
|
if (isLoading) {
|
||||||
|
return (
|
||||||
|
<div className="p-6 space-y-4">
|
||||||
|
<div className="h-6 w-64 bg-muted rounded animate-pulse" />
|
||||||
|
<div className="h-48 bg-muted rounded-xl animate-pulse" />
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!rate) {
|
||||||
|
return (
|
||||||
|
<div className="p-6">
|
||||||
|
<p className="text-muted-foreground">
|
||||||
|
{t('currencyRates.notFound', 'Walýuta kursy tapylmady')}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ─── Render ───────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="p-6">
|
||||||
|
|
||||||
|
|
||||||
|
{/* Header */}
|
||||||
|
<div className="flex items-center justify-between mb-6">
|
||||||
|
<h1 className="text-2xl font-semibold text-foreground">
|
||||||
|
{t('currencyRates.detail.title', 'Walýuta kursy giňişleýin')}: {rate.id}
|
||||||
|
</h1>
|
||||||
|
<div className="flex items-center gap-2">
|
||||||
|
<Button
|
||||||
|
variant="ghost"
|
||||||
|
size="icon"
|
||||||
|
className="text-muted-foreground hover:text-destructive"
|
||||||
|
onClick={() => setDeleteOpen(true)}
|
||||||
|
title={t('common.delete', 'Pozmak')}
|
||||||
|
>
|
||||||
|
<Trash2 size={18} />
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
variant="ghost"
|
||||||
|
size="icon"
|
||||||
|
className="text-muted-foreground hover:text-foreground"
|
||||||
|
onClick={() => navigate(`/resources/currency-rates/${rate.id}/edit`)}
|
||||||
|
title={t('common.edit', 'Üýtgetmek')}
|
||||||
|
>
|
||||||
|
<Pencil size={18} />
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Detail Card */}
|
||||||
|
<Section>
|
||||||
|
<InfoRow label="ID" value={rate.id} />
|
||||||
|
<InfoRow label={t('currencyRates.fields.currencyFrom', 'Currency from')} value={rate.currencyFrom} />
|
||||||
|
<InfoRow label={t('currencyRates.fields.currencyTo', 'Currency to')} value={rate.currencyTo} />
|
||||||
|
<InfoRow label={t('currencyRates.fields.value', 'Value')} value={rate.value} />
|
||||||
|
<InfoRow label={t('common.createdAt', 'Döredilen senesi')}
|
||||||
|
value={new Date(rate.createdAt).toLocaleString()}
|
||||||
|
/>
|
||||||
|
<InfoRow label={t('common.updatedAt', 'Üýtgedilen senesi')}
|
||||||
|
value={new Date(rate.updatedAt).toLocaleString()}
|
||||||
|
/>
|
||||||
|
</Section>
|
||||||
|
|
||||||
|
{/* Delete Dialog */}
|
||||||
|
<AlertDialog open={deleteOpen} onOpenChange={setDeleteOpen}>
|
||||||
|
<AlertDialogContent>
|
||||||
|
<AlertDialogHeader>
|
||||||
|
<AlertDialogTitle>
|
||||||
|
{t('currencyRates.deleteDialog.title', 'Pozmak isleýärsiňizmi?')}
|
||||||
|
</AlertDialogTitle>
|
||||||
|
<AlertDialogDescription>
|
||||||
|
{t(
|
||||||
|
'currencyRates.deleteDialog.description',
|
||||||
|
'Bu amal yzyna gaýtarylyp bilinmez. Walýuta kursy hemişelik pozular.'
|
||||||
|
)}
|
||||||
|
</AlertDialogDescription>
|
||||||
|
</AlertDialogHeader>
|
||||||
|
<AlertDialogFooter>
|
||||||
|
<AlertDialogCancel>{t('common.cancel', 'Ýatyr')}</AlertDialogCancel>
|
||||||
|
<AlertDialogAction
|
||||||
|
onClick={handleDeleteConfirm}
|
||||||
|
disabled={deleteMutation.isPending}
|
||||||
|
className="bg-destructive text-destructive-foreground hover:bg-destructive/90"
|
||||||
|
>
|
||||||
|
{deleteMutation.isPending
|
||||||
|
? t('common.deleting', 'Pozulýar...')
|
||||||
|
: t('common.delete', 'Pozmak')}
|
||||||
|
</AlertDialogAction>
|
||||||
|
</AlertDialogFooter>
|
||||||
|
</AlertDialogContent>
|
||||||
|
</AlertDialog>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -0,0 +1,204 @@
|
|||||||
|
// pages/VisaMasterSettingsPage.tsx
|
||||||
|
|
||||||
|
import { useState } from 'react'
|
||||||
|
import { useNavigate } from 'react-router-dom'
|
||||||
|
import { useTranslation } from 'react-i18next'
|
||||||
|
import { Pencil, Trash2 } from 'lucide-react'
|
||||||
|
import {
|
||||||
|
AlertDialog,
|
||||||
|
AlertDialogAction,
|
||||||
|
AlertDialogCancel,
|
||||||
|
AlertDialogContent,
|
||||||
|
AlertDialogDescription,
|
||||||
|
AlertDialogFooter,
|
||||||
|
AlertDialogHeader,
|
||||||
|
AlertDialogTitle,
|
||||||
|
} from '@/components/ui/alert-dialog'
|
||||||
|
import { Button } from '@/components/ui/button'
|
||||||
|
import { DataTable, type ColumnDef } from '@/components/dataTable'
|
||||||
|
import { DataTableToolbar } from '@/components/dataTableToolbar'
|
||||||
|
import {
|
||||||
|
useGetVisaMasterSettings,
|
||||||
|
useDeleteVisaMasterSetting,
|
||||||
|
} from '@/features/visaMasterSberSettings/hooks/useVisaMasterSettings'
|
||||||
|
import type { VisaMasterSetting } from '@/features/visaMasterSberSettings/api/visaMasterSberSettingsApi'
|
||||||
|
|
||||||
|
// ─── Column defaults ──────────────────────────────────────────────────────────
|
||||||
|
|
||||||
|
const DEFAULT_VISIBILITY = { id: true, kod: true, ady: true, yazgy: true }
|
||||||
|
const DEFAULT_ORDER = ['id', 'kod', 'ady', 'yazgy', 'actions']
|
||||||
|
|
||||||
|
// ─── VisaMasterSettingsPage ───────────────────────────────────────────────────
|
||||||
|
|
||||||
|
export default function VisaMasterSettingsPage() {
|
||||||
|
const { t } = useTranslation()
|
||||||
|
const navigate = useNavigate()
|
||||||
|
|
||||||
|
const [page, setPage] = useState(1)
|
||||||
|
const [perPage] = useState(25)
|
||||||
|
const [search, setSearch] = useState('')
|
||||||
|
const [columnVisibility, setColumnVisibility] = useState<Record<string, boolean>>(DEFAULT_VISIBILITY)
|
||||||
|
const [columnOrder, setColumnOrder] = useState(DEFAULT_ORDER)
|
||||||
|
const [deleteId, setDeleteId] = useState<number | null>(null)
|
||||||
|
|
||||||
|
const { data, isLoading } = useGetVisaMasterSettings({ page, perPage, search })
|
||||||
|
const deleteMutation = useDeleteVisaMasterSetting()
|
||||||
|
|
||||||
|
const handleDeleteConfirm = async () => {
|
||||||
|
if (deleteId === null) return
|
||||||
|
await deleteMutation.mutateAsync(deleteId)
|
||||||
|
setDeleteId(null)
|
||||||
|
}
|
||||||
|
|
||||||
|
const handleSearchChange = (val: string) => {
|
||||||
|
setSearch(val)
|
||||||
|
setPage(1)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ─── Columns ──────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
|
const columns: ColumnDef<VisaMasterSetting>[] = [
|
||||||
|
{
|
||||||
|
accessorKey: 'id',
|
||||||
|
header: 'ID',
|
||||||
|
cell: ({ row }) => (
|
||||||
|
<span className="text-primary font-semibold">{row.original.id}</span>
|
||||||
|
),
|
||||||
|
size: 80,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
accessorKey: 'kod',
|
||||||
|
header: t('visaMasterSettings.columns.kod', 'KOD'),
|
||||||
|
cell: ({ row }) => (
|
||||||
|
<span className="font-medium text-foreground font-mono text-xs">
|
||||||
|
{row.original.kod}
|
||||||
|
</span>
|
||||||
|
),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
accessorKey: 'ady',
|
||||||
|
header: t('visaMasterSettings.columns.ady', 'ADY'),
|
||||||
|
cell: ({ row }) => (
|
||||||
|
<span className="text-foreground">{row.original.ady}</span>
|
||||||
|
),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
accessorKey: 'yazgy',
|
||||||
|
header: t('visaMasterSettings.columns.yazgy', 'YAZGY'),
|
||||||
|
cell: ({ row }) => (
|
||||||
|
<span className="text-foreground line-clamp-1 max-w-xs">{row.original.yazgy}</span>
|
||||||
|
),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 'actions',
|
||||||
|
header: '',
|
||||||
|
enableSorting: false,
|
||||||
|
enableHiding: false,
|
||||||
|
cell: ({ row }) => (
|
||||||
|
<div className="flex items-center justify-end gap-1">
|
||||||
|
<Button
|
||||||
|
variant="ghost"
|
||||||
|
size="icon"
|
||||||
|
className="h-8 w-8 text-muted-foreground hover:text-foreground"
|
||||||
|
onClick={() =>
|
||||||
|
navigate(`/visa-master-sber-settings/${row.original.id}/edit`)
|
||||||
|
}
|
||||||
|
title={t('common.edit', 'Üýtgetmek')}
|
||||||
|
>
|
||||||
|
<Pencil size={15} />
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
variant="ghost"
|
||||||
|
size="icon"
|
||||||
|
className="h-8 w-8 text-muted-foreground hover:text-destructive"
|
||||||
|
onClick={() => setDeleteId(row.original.id)}
|
||||||
|
title={t('common.delete', 'Pozmak')}
|
||||||
|
>
|
||||||
|
<Trash2 size={15} />
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
),
|
||||||
|
size: 100,
|
||||||
|
},
|
||||||
|
]
|
||||||
|
|
||||||
|
const columnMeta = columns
|
||||||
|
.filter((c) => 'accessorKey' in c && c.accessorKey)
|
||||||
|
.map((c) => ({
|
||||||
|
id: String(('accessorKey' in c ? c.accessorKey : c.id) ?? ''),
|
||||||
|
label: typeof c.header === 'string' ? c.header : String(('accessorKey' in c ? c.accessorKey : '') ?? ''),
|
||||||
|
}))
|
||||||
|
|
||||||
|
// ─── Render ───────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="p-6">
|
||||||
|
|
||||||
|
|
||||||
|
<h1 className="text-2xl font-semibold text-foreground mb-5">
|
||||||
|
{t('visaMasterSettings.title', 'Visa/Master, Sber sazlamalar')}
|
||||||
|
</h1>
|
||||||
|
|
||||||
|
<DataTableToolbar
|
||||||
|
searchValue={search}
|
||||||
|
onSearchChange={handleSearchChange}
|
||||||
|
searchPlaceholder={t('common.search', 'Gözlemek')}
|
||||||
|
columns={columnMeta}
|
||||||
|
columnVisibility={columnVisibility}
|
||||||
|
onColumnVisibilityChange={setColumnVisibility}
|
||||||
|
columnOrder={columnOrder}
|
||||||
|
onColumnOrderChange={setColumnOrder}
|
||||||
|
actionLabel={t('visaMasterSettings.actions.create', 'Visa/Master, Sber sazlamalar dörediň')}
|
||||||
|
onAction={() => navigate('/visa-master-sber-settings/create')}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<DataTable
|
||||||
|
columns={columns}
|
||||||
|
data={data?.data ?? []}
|
||||||
|
isLoading={isLoading}
|
||||||
|
columnVisibility={columnVisibility}
|
||||||
|
onColumnVisibilityChange={setColumnVisibility}
|
||||||
|
columnOrder={columnOrder}
|
||||||
|
onColumnOrderChange={setColumnOrder}
|
||||||
|
enableRowSelection
|
||||||
|
getRowId={(row) => String(row.id)}
|
||||||
|
currentPage={page}
|
||||||
|
totalPages={data?.totalPages ?? 1}
|
||||||
|
totalCount={data?.total ?? 0}
|
||||||
|
onPageChange={setPage}
|
||||||
|
/>
|
||||||
|
|
||||||
|
{/* Delete Confirmation */}
|
||||||
|
<AlertDialog
|
||||||
|
open={deleteId !== null}
|
||||||
|
onOpenChange={(open) => { if (!open) setDeleteId(null) }}
|
||||||
|
>
|
||||||
|
<AlertDialogContent>
|
||||||
|
<AlertDialogHeader>
|
||||||
|
<AlertDialogTitle>
|
||||||
|
{t('visaMasterSettings.deleteDialog.title', 'Pozmak isleýärsiňizmi?')}
|
||||||
|
</AlertDialogTitle>
|
||||||
|
<AlertDialogDescription>
|
||||||
|
{t(
|
||||||
|
'visaMasterSettings.deleteDialog.description',
|
||||||
|
'Bu amal yzyna gaýtarylyp bilinmez. Sazlama hemişelik pozular.'
|
||||||
|
)}
|
||||||
|
</AlertDialogDescription>
|
||||||
|
</AlertDialogHeader>
|
||||||
|
<AlertDialogFooter>
|
||||||
|
<AlertDialogCancel>{t('common.cancel', 'Ýatyr')}</AlertDialogCancel>
|
||||||
|
<AlertDialogAction
|
||||||
|
onClick={handleDeleteConfirm}
|
||||||
|
disabled={deleteMutation.isPending}
|
||||||
|
className="bg-destructive text-destructive-foreground hover:bg-destructive/90"
|
||||||
|
>
|
||||||
|
{deleteMutation.isPending
|
||||||
|
? t('common.deleting', 'Pozulýar...')
|
||||||
|
: t('common.delete', 'Pozmak')}
|
||||||
|
</AlertDialogAction>
|
||||||
|
</AlertDialogFooter>
|
||||||
|
</AlertDialogContent>
|
||||||
|
</AlertDialog>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
// pages/VisaMasterSettingCreatePage.tsx
|
||||||
|
|
||||||
|
import { useTranslation } from 'react-i18next'
|
||||||
|
import { VisaMasterSettingForm } from '@/features/visaMasterSberSettings/components/visaMasterSberSettingsForm'
|
||||||
|
|
||||||
|
// ─── VisaMasterSettingCreatePage ──────────────────────────────────────────────
|
||||||
|
|
||||||
|
export default function VisaMasterSettingCreatePage() {
|
||||||
|
const { t } = useTranslation()
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="p-6">
|
||||||
|
|
||||||
|
|
||||||
|
<h1 className="text-2xl font-semibold text-foreground mb-6">
|
||||||
|
{t('visaMasterSettings.actions.create', 'Visa/Master, Sber sazlamalar dörediň')}
|
||||||
|
</h1>
|
||||||
|
|
||||||
|
<div className="bg-card border border-border rounded-xl overflow-hidden">
|
||||||
|
<VisaMasterSettingForm mode="create" />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -0,0 +1,57 @@
|
|||||||
|
// pages/VisaMasterSettingEditPage.tsx
|
||||||
|
|
||||||
|
import {useParams } from 'react-router-dom'
|
||||||
|
import { useTranslation } from 'react-i18next'
|
||||||
|
import { VisaMasterSettingForm } from '@/features/visaMasterSberSettings/components/visaMasterSberSettingsForm'
|
||||||
|
import { useGetVisaMasterSettingById } from '@/features/visaMasterSberSettings/hooks/useVisaMasterSettings'
|
||||||
|
|
||||||
|
// ─── VisaMasterSettingEditPage ────────────────────────────────────────────────
|
||||||
|
|
||||||
|
export default function VisaMasterSettingEditPage() {
|
||||||
|
const { id } = useParams<{ id: string }>()
|
||||||
|
const numericId = Number(id)
|
||||||
|
const { t } = useTranslation()
|
||||||
|
|
||||||
|
const { data: setting, isLoading } = useGetVisaMasterSettingById(numericId)
|
||||||
|
|
||||||
|
// ─── Loading skeleton ──────────────────────────────────────────────────────
|
||||||
|
|
||||||
|
if (isLoading) {
|
||||||
|
return (
|
||||||
|
<div className="p-6 space-y-4">
|
||||||
|
<div className="h-6 w-72 bg-muted rounded animate-pulse" />
|
||||||
|
<div className="h-56 bg-muted rounded-xl animate-pulse" />
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!setting) {
|
||||||
|
return (
|
||||||
|
<div className="p-6">
|
||||||
|
<p className="text-muted-foreground">
|
||||||
|
{t('visaMasterSettings.notFound', 'Sazlama tapylmady')}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ─── Render ───────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="p-6">
|
||||||
|
|
||||||
|
|
||||||
|
<h1 className="text-2xl font-semibold text-foreground mb-6">
|
||||||
|
{t('visaMasterSettings.detail.editTitle', 'Sazlamany üýtgetmek')}: {setting.id}
|
||||||
|
</h1>
|
||||||
|
|
||||||
|
<div className="bg-card border border-border rounded-xl overflow-hidden">
|
||||||
|
<VisaMasterSettingForm
|
||||||
|
mode="edit"
|
||||||
|
initialData={setting}
|
||||||
|
settingId={numericId}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -0,0 +1,208 @@
|
|||||||
|
// pages/OnlinePaymentHistoryPage.tsx
|
||||||
|
|
||||||
|
import { useState } from "react";
|
||||||
|
import { useNavigate } from "react-router-dom";
|
||||||
|
import { useTranslation } from "react-i18next";
|
||||||
|
import { Eye, Rss } from "lucide-react";
|
||||||
|
import { Button } from "@/components/ui/button";
|
||||||
|
import { DataTable, type ColumnDef } from "@/components/dataTable";
|
||||||
|
import { DataTableToolbar } from "@/components/dataTableToolbar";
|
||||||
|
import type { VisibilityState } from "@tanstack/react-table";
|
||||||
|
import {
|
||||||
|
useGetOnlinePayments,
|
||||||
|
useTriggerPaymentCallback,
|
||||||
|
} from "@/features/onlinePaymentHistory/hooks/useOnlinePaymentsHistory";
|
||||||
|
import type { OnlinePayment } from "@/features/onlinePaymentHistory/api/onlinePaymentsHistoryApi";
|
||||||
|
import { PaymentStatusBadge } from "../../features/onlinePaymentHistory/components/PaymentStatusBadge";
|
||||||
|
|
||||||
|
// ─── Defaults ─────────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
|
const DEFAULT_VISIBILITY = {
|
||||||
|
amount: true,
|
||||||
|
apiClient: true,
|
||||||
|
description: true,
|
||||||
|
status: true,
|
||||||
|
username: true,
|
||||||
|
createdAt: true,
|
||||||
|
};
|
||||||
|
const DEFAULT_ORDER = [
|
||||||
|
"amount",
|
||||||
|
"apiClient",
|
||||||
|
"description",
|
||||||
|
"status",
|
||||||
|
"username",
|
||||||
|
"createdAt",
|
||||||
|
"actions",
|
||||||
|
];
|
||||||
|
|
||||||
|
// ─── OnlinePaymentHistoryPage ─────────────────────────────────────────────────
|
||||||
|
|
||||||
|
export default function OnlinePaymentHistoryPage() {
|
||||||
|
const { t } = useTranslation();
|
||||||
|
const navigate = useNavigate();
|
||||||
|
|
||||||
|
const [page, setPage] = useState(1);
|
||||||
|
const [perPage] = useState(25);
|
||||||
|
const [search, setSearch] = useState("");
|
||||||
|
const [columnVisibility, setColumnVisibility] =
|
||||||
|
useState<VisibilityState>(DEFAULT_VISIBILITY);
|
||||||
|
const [columnOrder, setColumnOrder] = useState(DEFAULT_ORDER);
|
||||||
|
|
||||||
|
const { data, isLoading } = useGetOnlinePayments({ page, perPage, search });
|
||||||
|
const callbackMutation = useTriggerPaymentCallback();
|
||||||
|
|
||||||
|
const handleSearchChange = (val: string) => {
|
||||||
|
setSearch(val);
|
||||||
|
setPage(1);
|
||||||
|
};
|
||||||
|
|
||||||
|
// ─── Columns ──────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
|
const columns: ColumnDef<OnlinePayment>[] = [
|
||||||
|
{
|
||||||
|
accessorKey: "amount",
|
||||||
|
header: t("onlinePayments.columns.amount", "MÖÇBERI"),
|
||||||
|
cell: ({ row }) => (
|
||||||
|
<span className="tabular-nums text-foreground font-medium">
|
||||||
|
{row.original.amount}
|
||||||
|
</span>
|
||||||
|
),
|
||||||
|
size: 100,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
accessorKey: "apiClient",
|
||||||
|
header: t("onlinePayments.columns.apiClient", "API CLIENT"),
|
||||||
|
cell: ({ row }) => (
|
||||||
|
<span className="text-foreground text-xs font-mono truncate max-w-[180px] block">
|
||||||
|
{row.original.apiClient}
|
||||||
|
</span>
|
||||||
|
),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
accessorKey: "description",
|
||||||
|
header: t("onlinePayments.columns.description", "DESC"),
|
||||||
|
cell: ({ row }) => (
|
||||||
|
<span className="text-foreground text-sm">
|
||||||
|
{row.original.description}
|
||||||
|
</span>
|
||||||
|
),
|
||||||
|
size: 140,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
accessorKey: "status",
|
||||||
|
header: t("onlinePayments.columns.status", "STATUS"),
|
||||||
|
cell: ({ row }) => <PaymentStatusBadge status={row.original.status} />,
|
||||||
|
size: 140,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
accessorKey: "username",
|
||||||
|
header: t("onlinePayments.columns.username", "USERNAME"),
|
||||||
|
cell: ({ row }) => (
|
||||||
|
<span className="text-foreground text-xs font-mono">
|
||||||
|
{row.original.username}
|
||||||
|
</span>
|
||||||
|
),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
accessorKey: "createdAt",
|
||||||
|
header: t("onlinePayments.columns.createdAt", "DÖREDILEN WAGTY"),
|
||||||
|
cell: ({ row }) => (
|
||||||
|
<span className="text-muted-foreground text-xs whitespace-nowrap">
|
||||||
|
{formatDateTime(row.original.createdAt)}
|
||||||
|
</span>
|
||||||
|
),
|
||||||
|
size: 140,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: "actions",
|
||||||
|
header: "",
|
||||||
|
enableSorting: false,
|
||||||
|
enableHiding: false,
|
||||||
|
cell: ({ row }) => (
|
||||||
|
<div className="flex items-center justify-end gap-1">
|
||||||
|
{/* Callback trigger */}
|
||||||
|
<Button
|
||||||
|
variant="ghost"
|
||||||
|
size="icon"
|
||||||
|
className="h-8 w-8 text-muted-foreground hover:text-foreground"
|
||||||
|
disabled={callbackMutation.isPending}
|
||||||
|
onClick={() => callbackMutation.mutate(row.original.id)}
|
||||||
|
title={t("onlinePayments.actions.callback", "Callback ugrat")}
|
||||||
|
>
|
||||||
|
<Rss size={15} />
|
||||||
|
</Button>
|
||||||
|
{/* View detail */}
|
||||||
|
<Button
|
||||||
|
variant="ghost"
|
||||||
|
size="icon"
|
||||||
|
className="h-8 w-8 text-muted-foreground hover:text-foreground"
|
||||||
|
onClick={() =>
|
||||||
|
navigate(`/online-payments-history/${row.original.id}`)
|
||||||
|
}
|
||||||
|
title={t("common.view", "Görmek")}
|
||||||
|
>
|
||||||
|
<Eye size={15} />
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
),
|
||||||
|
size: 90,
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
const columnMeta = columns
|
||||||
|
.filter((c) => "accessorKey" in c && c.accessorKey)
|
||||||
|
.map((c) => ({
|
||||||
|
id: String(("accessorKey" in c ? c.accessorKey : c.id) ?? ""),
|
||||||
|
label: typeof c.header === "string" ? c.header : "",
|
||||||
|
}));
|
||||||
|
|
||||||
|
// ─── Render ───────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="p-6">
|
||||||
|
<h1 className="text-2xl font-semibold text-foreground mb-5">
|
||||||
|
{t("onlinePayments.title", "Onlaýn töleg taryhy")}
|
||||||
|
</h1>
|
||||||
|
|
||||||
|
<DataTableToolbar
|
||||||
|
searchValue={search}
|
||||||
|
onSearchChange={handleSearchChange}
|
||||||
|
searchPlaceholder={t("common.search", "Gözlemek")}
|
||||||
|
columns={columnMeta}
|
||||||
|
columnVisibility={columnVisibility}
|
||||||
|
onColumnVisibilityChange={setColumnVisibility}
|
||||||
|
columnOrder={columnOrder}
|
||||||
|
onColumnOrderChange={setColumnOrder}
|
||||||
|
hideAction
|
||||||
|
/>
|
||||||
|
|
||||||
|
<DataTable
|
||||||
|
columns={columns}
|
||||||
|
data={data?.data ?? []}
|
||||||
|
isLoading={isLoading}
|
||||||
|
columnVisibility={columnVisibility}
|
||||||
|
onColumnVisibilityChange={setColumnVisibility}
|
||||||
|
columnOrder={columnOrder}
|
||||||
|
onColumnOrderChange={setColumnOrder}
|
||||||
|
enableRowSelection
|
||||||
|
getRowId={(row) => String(row.id)}
|
||||||
|
currentPage={page}
|
||||||
|
totalPages={data?.totalPages ?? 1}
|
||||||
|
totalCount={data?.total ?? 0}
|
||||||
|
onPageChange={setPage}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// ─── Helpers ──────────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
|
function formatDateTime(iso: string): string {
|
||||||
|
const d = new Date(iso);
|
||||||
|
const hh = String(d.getHours()).padStart(2, "0");
|
||||||
|
const mm = String(d.getMinutes()).padStart(2, "0");
|
||||||
|
const dd = String(d.getDate()).padStart(2, "0");
|
||||||
|
const mo = String(d.getMonth() + 1).padStart(2, "0");
|
||||||
|
const yy = d.getFullYear();
|
||||||
|
return `${hh}:${mm}, ${dd}.${mo}.${yy}`;
|
||||||
|
}
|
||||||
@@ -0,0 +1,130 @@
|
|||||||
|
// pages/OnlinePaymentDetailPage.tsx
|
||||||
|
|
||||||
|
import { useParams } from "react-router-dom";
|
||||||
|
import { useTranslation } from "react-i18next";
|
||||||
|
import { Section, InfoRow } from "@/components/viewPageComponents";
|
||||||
|
import { useGetOnlinePaymentById } from "@/features/onlinePaymentHistory/hooks/useOnlinePaymentsHistory";
|
||||||
|
import { PaymentStatusBadge } from "../../features/onlinePaymentHistory/components/PaymentStatusBadge";
|
||||||
|
|
||||||
|
// ─── OnlinePaymentDetailPage ──────────────────────────────────────────────────
|
||||||
|
|
||||||
|
export default function OnlinePaymentDetailPage() {
|
||||||
|
const { id } = useParams<{ id: string }>();
|
||||||
|
const numericId = Number(id);
|
||||||
|
const { t } = useTranslation();
|
||||||
|
|
||||||
|
const { data: payment, isLoading } = useGetOnlinePaymentById(numericId);
|
||||||
|
|
||||||
|
// ─── Loading skeleton ──────────────────────────────────────────────────────
|
||||||
|
|
||||||
|
if (isLoading) {
|
||||||
|
return (
|
||||||
|
<div className="p-6 space-y-4">
|
||||||
|
<div className="h-6 w-96 bg-muted rounded animate-pulse" />
|
||||||
|
<div className="h-[560px] bg-muted rounded-xl animate-pulse" />
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!payment) {
|
||||||
|
return (
|
||||||
|
<div className="p-6">
|
||||||
|
<p className="text-muted-foreground">
|
||||||
|
{t("onlinePayments.notFound", "Töleg tapylmady")}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const title = `${t("onlinePayments.detail.title", "Onlaýn töleg taryhy giňişleýin")}: ${payment.orderId}`;
|
||||||
|
|
||||||
|
// ─── Render ───────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="p-6">
|
||||||
|
<h1 className="text-xl font-semibold text-foreground mb-6 break-all">
|
||||||
|
{title}
|
||||||
|
</h1>
|
||||||
|
|
||||||
|
{/* Detail Card */}
|
||||||
|
<Section>
|
||||||
|
<InfoRow label="ID" value={payment.id} />
|
||||||
|
<InfoRow
|
||||||
|
label={t("onlinePayments.fields.amount", "amount")}
|
||||||
|
value={payment.amount}
|
||||||
|
/>
|
||||||
|
<InfoRow
|
||||||
|
label={t("onlinePayments.fields.orderNumber", "orderNumber")}
|
||||||
|
value={payment.orderNumber}
|
||||||
|
/>
|
||||||
|
<InfoRow
|
||||||
|
label={t("onlinePayments.fields.apiClient", "Api Client")}
|
||||||
|
value={payment.apiClient}
|
||||||
|
/>
|
||||||
|
<InfoRow
|
||||||
|
label={t("onlinePayments.fields.description", "description")}
|
||||||
|
value={payment.description}
|
||||||
|
/>
|
||||||
|
<InfoRow
|
||||||
|
label={t("onlinePayments.fields.orderId", "orderId")}
|
||||||
|
value={payment.orderId}
|
||||||
|
/>
|
||||||
|
<InfoRow
|
||||||
|
label={t("onlinePayments.fields.formUrl", "formUrl")}
|
||||||
|
isLink
|
||||||
|
value={payment.formUrl}
|
||||||
|
/>
|
||||||
|
<InfoRow
|
||||||
|
label={t("onlinePayments.fields.successUrl", "successUrl")}
|
||||||
|
isLink
|
||||||
|
value={payment.successUrl}
|
||||||
|
/>
|
||||||
|
<InfoRow label={t("onlinePayments.fields.status", "Status")}>
|
||||||
|
<PaymentStatusBadge status={payment.status} />
|
||||||
|
</InfoRow>
|
||||||
|
<InfoRow
|
||||||
|
label={t("onlinePayments.fields.callbackStatus", "callbackStatus")}
|
||||||
|
value={payment.callbackStatus ?? "—"}
|
||||||
|
/>
|
||||||
|
<InfoRow
|
||||||
|
label={t("onlinePayments.fields.username", "username")}
|
||||||
|
value={payment.username}
|
||||||
|
/>
|
||||||
|
<InfoRow
|
||||||
|
label={t(
|
||||||
|
"onlinePayments.fields.onlinePaymantableId",
|
||||||
|
"online_paymantable_id",
|
||||||
|
)}
|
||||||
|
value={payment.onlinePaymantableId}
|
||||||
|
/>
|
||||||
|
<InfoRow
|
||||||
|
label={t(
|
||||||
|
"onlinePayments.fields.onlinePaymantableType",
|
||||||
|
"online_paymantable_type",
|
||||||
|
)}
|
||||||
|
value={payment.onlinePaymantableType}
|
||||||
|
/>
|
||||||
|
<InfoRow
|
||||||
|
label={t("onlinePayments.fields.createdAt", "Döredilen wagty")}
|
||||||
|
value={formatDateTime(payment.createdAt)}
|
||||||
|
/>
|
||||||
|
<InfoRow
|
||||||
|
label={t("onlinePayments.fields.updatedAt", "Updated at")}
|
||||||
|
value={formatDateTime(payment.updatedAt)}
|
||||||
|
/>
|
||||||
|
</Section>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// ─── Helpers ──────────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
|
function formatDateTime(iso: string): string {
|
||||||
|
const d = new Date(iso);
|
||||||
|
const hh = String(d.getHours()).padStart(2, "0");
|
||||||
|
const mm = String(d.getMinutes()).padStart(2, "0");
|
||||||
|
const dd = String(d.getDate()).padStart(2, "0");
|
||||||
|
const mo = String(d.getMonth() + 1).padStart(2, "0");
|
||||||
|
const yy = d.getFullYear();
|
||||||
|
return `${hh}:${mm}, ${dd}.${mo}.${yy}`;
|
||||||
|
}
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
import { useTranslation } from 'react-i18next'
|
||||||
|
import { RoleForm } from '@/features/roles/components/roleForm'
|
||||||
|
|
||||||
|
export default function RoleCreatePage() {
|
||||||
|
const { t } = useTranslation()
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
<h1 className="text-2xl font-bold text-foreground mb-6">
|
||||||
|
{t('roles.actions.create', 'Rol dörediň')}
|
||||||
|
</h1>
|
||||||
|
<RoleForm mode="create" />
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -0,0 +1,46 @@
|
|||||||
|
import { useParams } from 'react-router-dom'
|
||||||
|
import { useTranslation } from 'react-i18next'
|
||||||
|
import { RoleForm } from '@/features/roles/components/roleForm'
|
||||||
|
import { useRole } from '@/features/roles/hooks/useRoles'
|
||||||
|
import { Skeleton } from '@/components/ui/skeleton'
|
||||||
|
|
||||||
|
export default function RoleEditPage() {
|
||||||
|
const { t } = useTranslation()
|
||||||
|
const { id } = useParams<{ id: string }>()
|
||||||
|
const roleId = Number(id)
|
||||||
|
|
||||||
|
const { data: role, isLoading, isError } = useRole(roleId)
|
||||||
|
|
||||||
|
if (isLoading) {
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
<Skeleton className="h-8 w-48 mb-6" />
|
||||||
|
<div className="bg-card border border-border rounded-xl overflow-hidden divide-y divide-border">
|
||||||
|
{Array.from({ length: 3 }).map((_, i) => (
|
||||||
|
<div key={i} className="grid grid-cols-[220px_1fr] items-center p-5">
|
||||||
|
<Skeleton className="h-4 w-24" />
|
||||||
|
<Skeleton className="h-9 w-full" />
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isError || !role) {
|
||||||
|
return (
|
||||||
|
<p className="text-destructive text-sm">
|
||||||
|
{t('common.fetchError', 'Maglumat ýüklenmedi.')}
|
||||||
|
</p>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
<h1 className="text-2xl font-bold text-foreground mb-6">
|
||||||
|
{t('roles.editTitle', 'Rol üýtget')}: {role.name?.tk}
|
||||||
|
</h1>
|
||||||
|
<RoleForm mode="edit" initialData={role} roleId={roleId} />
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -0,0 +1,194 @@
|
|||||||
|
import { useState } from 'react'
|
||||||
|
import { useNavigate } from 'react-router-dom'
|
||||||
|
import { useTranslation } from 'react-i18next'
|
||||||
|
import { Eye, Pencil, Trash2 } from 'lucide-react'
|
||||||
|
import type { ColumnDef, VisibilityState } from '@tanstack/react-table'
|
||||||
|
import { DataTable } from '@/components/dataTable'
|
||||||
|
import { DataTableToolbar } from '@/components/dataTableToolbar'
|
||||||
|
import { Button } from '@/components/ui/button'
|
||||||
|
import {
|
||||||
|
AlertDialog,
|
||||||
|
AlertDialogAction,
|
||||||
|
AlertDialogCancel,
|
||||||
|
AlertDialogContent,
|
||||||
|
AlertDialogDescription,
|
||||||
|
AlertDialogFooter,
|
||||||
|
AlertDialogHeader,
|
||||||
|
AlertDialogTitle,
|
||||||
|
} from '@/components/ui/alert-dialog'
|
||||||
|
import { usePermissions, useDeletePermission } from '@/features/permissions/hooks/usePermissions'
|
||||||
|
import type { Permission } from '@/features/permissions/api/permissionsApi'
|
||||||
|
|
||||||
|
// ─── Column meta for toolbar ──────────────────────────────────────────────────
|
||||||
|
|
||||||
|
const COLUMN_META = [
|
||||||
|
{ id: 'id', label: 'ID' },
|
||||||
|
{ id: 'code', label: 'Kod' },
|
||||||
|
{ id: 'name', label: 'Ady' },
|
||||||
|
{ id: 'guard_name', label: 'Guard name' },
|
||||||
|
]
|
||||||
|
|
||||||
|
// ─── PermissionsPage ──────────────────────────────────────────────────────────
|
||||||
|
|
||||||
|
export default function PermissionsPage() {
|
||||||
|
const { t } = useTranslation()
|
||||||
|
const navigate = useNavigate()
|
||||||
|
|
||||||
|
// ── State ──────────────────────────────────────────────────────────────────
|
||||||
|
const [search, setSearch] = useState('')
|
||||||
|
const [page, setPage] = useState(1)
|
||||||
|
const [perPage, setPerPage] = useState(25)
|
||||||
|
const [columnVisibility, setColumnVisibility] = useState<VisibilityState>({})
|
||||||
|
const [columnOrder, setColumnOrder] = useState<string[]>([])
|
||||||
|
const [deleteId, setDeleteId] = useState<number | null>(null)
|
||||||
|
|
||||||
|
// ── Data ───────────────────────────────────────────────────────────────────
|
||||||
|
const { data, isLoading } = usePermissions({ search, page, per_page: perPage })
|
||||||
|
const deletePermission = useDeletePermission()
|
||||||
|
|
||||||
|
// ── Columns ────────────────────────────────────────────────────────────────
|
||||||
|
const columns: ColumnDef<Permission>[] = [
|
||||||
|
{
|
||||||
|
accessorKey: 'id',
|
||||||
|
header: 'ID',
|
||||||
|
size: 70,
|
||||||
|
cell: ({ row }) => (
|
||||||
|
<span className="text-primary font-semibold">{row.original.id}</span>
|
||||||
|
),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
accessorKey: 'code',
|
||||||
|
header: t('permissions.fields.code', 'Kod'),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
accessorKey: 'name',
|
||||||
|
header: t('permissions.fields.name', 'Ady'),
|
||||||
|
cell: ({ row }) => <span>{row.original.name?.tk ?? '—'}</span>,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
accessorKey: 'guard_name',
|
||||||
|
header: 'Guard name',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 'actions',
|
||||||
|
header: '',
|
||||||
|
size: 120,
|
||||||
|
enableSorting: false,
|
||||||
|
enableHiding: false,
|
||||||
|
cell: ({ row }) => (
|
||||||
|
<div className="flex items-center justify-end gap-1">
|
||||||
|
<Button
|
||||||
|
variant="ghost"
|
||||||
|
size="icon"
|
||||||
|
className="h-8 w-8 text-muted-foreground hover:text-primary"
|
||||||
|
onClick={() => navigate(`/settings/users/permissions/${row.original.id}`)}
|
||||||
|
>
|
||||||
|
<Eye size={15} />
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
variant="ghost"
|
||||||
|
size="icon"
|
||||||
|
className="h-8 w-8 text-muted-foreground hover:text-blue-500"
|
||||||
|
onClick={() => navigate(`/settings/users/permissions/${row.original.id}/edit`)}
|
||||||
|
>
|
||||||
|
<Pencil size={15} />
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
variant="ghost"
|
||||||
|
size="icon"
|
||||||
|
className="h-8 w-8 text-muted-foreground hover:text-destructive"
|
||||||
|
onClick={() => setDeleteId(row.original.id)}
|
||||||
|
>
|
||||||
|
<Trash2 size={15} />
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
),
|
||||||
|
},
|
||||||
|
]
|
||||||
|
|
||||||
|
// ── Handlers ───────────────────────────────────────────────────────────────
|
||||||
|
const handleConfirmDelete = () => {
|
||||||
|
if (deleteId === null) return
|
||||||
|
deletePermission.mutate(deleteId, {
|
||||||
|
onSuccess: () => setDeleteId(null),
|
||||||
|
onError: () => setDeleteId(null),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// ── Render ─────────────────────────────────────────────────────────────────
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
{/* Page heading */}
|
||||||
|
<div className="flex items-center justify-between mb-6">
|
||||||
|
<h1 className="text-2xl font-bold text-foreground">
|
||||||
|
{t('permissions.title', 'Rugsatlar')}
|
||||||
|
</h1>
|
||||||
|
<Button onClick={() => navigate('/settings/users/permissions/create')}>
|
||||||
|
{t('permissions.actions.create', 'Rugsat dörediň')}
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Toolbar */}
|
||||||
|
<DataTableToolbar
|
||||||
|
searchValue={search}
|
||||||
|
onSearchChange={(v) => { setSearch(v); setPage(1) }}
|
||||||
|
searchPlaceholder={t('permissions.searchPlaceholder', 'Gözlemek...')}
|
||||||
|
columns={COLUMN_META}
|
||||||
|
columnVisibility={columnVisibility}
|
||||||
|
onColumnVisibilityChange={setColumnVisibility}
|
||||||
|
columnOrder={columnOrder}
|
||||||
|
onColumnOrderChange={setColumnOrder}
|
||||||
|
perPageOptions={[10, 25, 50, 100]}
|
||||||
|
perPage={perPage}
|
||||||
|
onPerPageChange={(v) => { setPerPage(v); setPage(1) }}
|
||||||
|
/>
|
||||||
|
|
||||||
|
{/* Table */}
|
||||||
|
<DataTable
|
||||||
|
columns={columns}
|
||||||
|
data={data?.data ?? []}
|
||||||
|
isLoading={isLoading}
|
||||||
|
columnVisibility={columnVisibility}
|
||||||
|
onColumnVisibilityChange={setColumnVisibility}
|
||||||
|
columnOrder={columnOrder}
|
||||||
|
onColumnOrderChange={setColumnOrder}
|
||||||
|
getRowId={(row) => String(row.id)}
|
||||||
|
currentPage={data?.meta?.current_page ?? 1}
|
||||||
|
totalPages={data?.meta?.last_page ?? 1}
|
||||||
|
totalCount={data?.meta?.total ?? 0}
|
||||||
|
onPageChange={setPage}
|
||||||
|
/>
|
||||||
|
|
||||||
|
{/* Delete confirmation dialog */}
|
||||||
|
<AlertDialog
|
||||||
|
open={deleteId !== null}
|
||||||
|
onOpenChange={(open) => { if (!open) setDeleteId(null) }}
|
||||||
|
>
|
||||||
|
<AlertDialogContent>
|
||||||
|
<AlertDialogHeader>
|
||||||
|
<AlertDialogTitle>
|
||||||
|
{t('permissions.deleteDialog.title', 'Rugsaty pozmak')}
|
||||||
|
</AlertDialogTitle>
|
||||||
|
<AlertDialogDescription>
|
||||||
|
{t(
|
||||||
|
'permissions.deleteDialog.description',
|
||||||
|
'Bu rugsaty pozmak isleýärsiňizmi? Bu amal yzyna gaýtarylmaz.',
|
||||||
|
)}
|
||||||
|
</AlertDialogDescription>
|
||||||
|
</AlertDialogHeader>
|
||||||
|
<AlertDialogFooter>
|
||||||
|
<AlertDialogCancel>{t('common.cancel', 'Ýatyr')}</AlertDialogCancel>
|
||||||
|
<AlertDialogAction
|
||||||
|
onClick={handleConfirmDelete}
|
||||||
|
className="bg-destructive text-destructive-foreground hover:bg-destructive/90"
|
||||||
|
>
|
||||||
|
{deletePermission.isPending
|
||||||
|
? t('common.deleting', 'Pozulýar...')
|
||||||
|
: t('common.delete', 'Poz')}
|
||||||
|
</AlertDialogAction>
|
||||||
|
</AlertDialogFooter>
|
||||||
|
</AlertDialogContent>
|
||||||
|
</AlertDialog>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
import { useTranslation } from 'react-i18next'
|
||||||
|
import { PermissionForm } from '@/features/permissions/components/permissionsForm'
|
||||||
|
|
||||||
|
export default function PermissionCreatePage() {
|
||||||
|
const { t } = useTranslation()
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
<h1 className="text-2xl font-bold text-foreground mb-6">
|
||||||
|
{t('permissions.actions.create', 'Rugsat dörediň')}
|
||||||
|
</h1>
|
||||||
|
<PermissionForm mode="create" />
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -0,0 +1,46 @@
|
|||||||
|
import { useParams } from 'react-router-dom'
|
||||||
|
import { useTranslation } from 'react-i18next'
|
||||||
|
import { PermissionForm } from '@/features/permissions/components/permissionsForm'
|
||||||
|
import { usePermission } from '@/features/permissions/hooks/usePermissions'
|
||||||
|
import { Skeleton } from '@/components/ui/skeleton'
|
||||||
|
|
||||||
|
export default function PermissionEditPage() {
|
||||||
|
const { t } = useTranslation()
|
||||||
|
const { id } = useParams<{ id: string }>()
|
||||||
|
const permissionId = Number(id)
|
||||||
|
|
||||||
|
const { data: permission, isLoading, isError } = usePermission(permissionId)
|
||||||
|
|
||||||
|
if (isLoading) {
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
<Skeleton className="h-8 w-56 mb-6" />
|
||||||
|
<div className="bg-card border border-border rounded-xl overflow-hidden divide-y divide-border">
|
||||||
|
{Array.from({ length: 3 }).map((_, i) => (
|
||||||
|
<div key={i} className="grid grid-cols-[220px_1fr] items-center p-5">
|
||||||
|
<Skeleton className="h-4 w-24" />
|
||||||
|
<Skeleton className="h-9 w-full" />
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isError || !permission) {
|
||||||
|
return (
|
||||||
|
<p className="text-destructive text-sm">
|
||||||
|
{t('common.fetchError', 'Maglumat ýüklenmedi.')}
|
||||||
|
</p>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
<h1 className="text-2xl font-bold text-foreground mb-6">
|
||||||
|
{t('permissions.editTitle', 'Rugsaty üýtget')}: {permission.name?.tk}
|
||||||
|
</h1>
|
||||||
|
<PermissionForm mode="edit" initialData={permission} permissionId={permissionId} />
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -0,0 +1,181 @@
|
|||||||
|
import { useState } from 'react'
|
||||||
|
import { useParams, useNavigate } from 'react-router-dom'
|
||||||
|
import { useTranslation } from 'react-i18next'
|
||||||
|
import { Pencil, Trash2 } from 'lucide-react'
|
||||||
|
import { Button } from '@/components/ui/button'
|
||||||
|
import {
|
||||||
|
AlertDialog,
|
||||||
|
AlertDialogAction,
|
||||||
|
AlertDialogCancel,
|
||||||
|
AlertDialogContent,
|
||||||
|
AlertDialogDescription,
|
||||||
|
AlertDialogFooter,
|
||||||
|
AlertDialogHeader,
|
||||||
|
AlertDialogTitle,
|
||||||
|
} from '@/components/ui/alert-dialog'
|
||||||
|
import { Skeleton } from '@/components/ui/skeleton'
|
||||||
|
import { Section, InfoRow } from '@/components/viewPageComponents'
|
||||||
|
import { usePermission, useDeletePermission } from '@/features/permissions/hooks/usePermissions'
|
||||||
|
|
||||||
|
// ─── LangTabs ─────────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
|
type LangKey = 'tk' | 'ru' | 'en'
|
||||||
|
|
||||||
|
const LANG_TABS: { key: LangKey; label: string }[] = [
|
||||||
|
{ key: 'tk', label: 'Türkmen' },
|
||||||
|
{ key: 'ru', label: 'Русский' },
|
||||||
|
{ key: 'en', label: 'English' },
|
||||||
|
]
|
||||||
|
|
||||||
|
function LangTabs({
|
||||||
|
active,
|
||||||
|
onChange,
|
||||||
|
}: {
|
||||||
|
active: LangKey
|
||||||
|
onChange: (l: LangKey) => void
|
||||||
|
}) {
|
||||||
|
return (
|
||||||
|
<div className="flex gap-1 justify-end mb-2">
|
||||||
|
{LANG_TABS.map((tab) => (
|
||||||
|
<button
|
||||||
|
key={tab.key}
|
||||||
|
type="button"
|
||||||
|
onClick={() => onChange(tab.key)}
|
||||||
|
className={`px-3 py-0.5 text-xs font-medium rounded-md transition-colors ${
|
||||||
|
active === tab.key
|
||||||
|
? 'text-primary border-b-2 border-primary'
|
||||||
|
: 'text-muted-foreground hover:text-foreground'
|
||||||
|
}`}
|
||||||
|
>
|
||||||
|
{tab.label}
|
||||||
|
</button>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ─── PermissionViewPage ───────────────────────────────────────────────────────
|
||||||
|
|
||||||
|
export default function PermissionViewPage() {
|
||||||
|
const { t } = useTranslation()
|
||||||
|
const { id } = useParams<{ id: string }>()
|
||||||
|
const navigate = useNavigate()
|
||||||
|
const permissionId = Number(id)
|
||||||
|
|
||||||
|
const [activeLang, setActiveLang] = useState<LangKey>('tk')
|
||||||
|
const [showDelete, setShowDelete] = useState(false)
|
||||||
|
|
||||||
|
const { data: permission, isLoading, isError } = usePermission(permissionId)
|
||||||
|
const deletePermission = useDeletePermission()
|
||||||
|
|
||||||
|
const handleConfirmDelete = () => {
|
||||||
|
deletePermission.mutate(permissionId, {
|
||||||
|
onSuccess: () => navigate('/settings/users/permissions'),
|
||||||
|
onError: () => setShowDelete(false),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// ── Loading skeleton ───────────────────────────────────────────────────────
|
||||||
|
if (isLoading) {
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
<Skeleton className="h-8 w-72 mb-6" />
|
||||||
|
<div className="bg-card border border-border rounded-xl overflow-hidden divide-y divide-border">
|
||||||
|
{Array.from({ length: 4 }).map((_, i) => (
|
||||||
|
<div key={i} className="grid grid-cols-[220px_1fr] items-center py-3 px-4">
|
||||||
|
<Skeleton className="h-4 w-20" />
|
||||||
|
<Skeleton className="h-4 w-40" />
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isError || !permission) {
|
||||||
|
return (
|
||||||
|
<p className="text-destructive text-sm">
|
||||||
|
{t('common.fetchError', 'Maglumat ýüklenmedi.')}
|
||||||
|
</p>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ── Render ─────────────────────────────────────────────────────────────────
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
{/* Page heading + actions */}
|
||||||
|
<div className="flex items-start justify-between mb-6">
|
||||||
|
<h1 className="text-2xl font-bold text-foreground">
|
||||||
|
{t('permissions.viewTitle', 'Rugsat giňişleýin')}: {permission.name?.tk}
|
||||||
|
</h1>
|
||||||
|
<div className="flex items-center gap-2">
|
||||||
|
<Button
|
||||||
|
variant="outline"
|
||||||
|
size="icon"
|
||||||
|
className="text-muted-foreground hover:text-destructive hover:border-destructive"
|
||||||
|
onClick={() => setShowDelete(true)}
|
||||||
|
>
|
||||||
|
<Trash2 size={16} />
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
variant="outline"
|
||||||
|
size="icon"
|
||||||
|
className="text-muted-foreground hover:text-blue-500 hover:border-blue-500"
|
||||||
|
onClick={() => navigate(`/settings/users/permissions/${permissionId}/edit`)}
|
||||||
|
>
|
||||||
|
<Pencil size={16} />
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Detail section */}
|
||||||
|
<Section>
|
||||||
|
<InfoRow label="ID" value={permission.id} />
|
||||||
|
<InfoRow label={t('permissions.fields.code', 'Kod')} value={permission.code} />
|
||||||
|
|
||||||
|
{/* Name row — with lang switcher */}
|
||||||
|
<div className="grid grid-cols-[220px_1fr] items-start py-2.5 px-4 border-b border-border">
|
||||||
|
<span className="text-sm text-muted-foreground pt-1">
|
||||||
|
{t('permissions.fields.name', 'Ady')}
|
||||||
|
</span>
|
||||||
|
<div>
|
||||||
|
<LangTabs active={activeLang} onChange={setActiveLang} />
|
||||||
|
<span className="text-sm text-foreground">
|
||||||
|
{permission.name?.[activeLang] || '—'}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<InfoRow label={t('permissions.fields.guardName', 'Guard name')} value={permission.guard_name} />
|
||||||
|
</Section>
|
||||||
|
|
||||||
|
{/* Delete dialog */}
|
||||||
|
<AlertDialog open={showDelete} onOpenChange={setShowDelete}>
|
||||||
|
<AlertDialogContent>
|
||||||
|
<AlertDialogHeader>
|
||||||
|
<AlertDialogTitle>
|
||||||
|
{t('permissions.deleteDialog.title', 'Rugsaty pozmak')}
|
||||||
|
</AlertDialogTitle>
|
||||||
|
<AlertDialogDescription>
|
||||||
|
{t(
|
||||||
|
'permissions.deleteDialog.description',
|
||||||
|
'Bu rugsaty pozmak isleýärsiňizmi? Bu amal yzyna gaýtarylmaz.',
|
||||||
|
)}
|
||||||
|
</AlertDialogDescription>
|
||||||
|
</AlertDialogHeader>
|
||||||
|
<AlertDialogFooter>
|
||||||
|
<AlertDialogCancel>{t('common.cancel', 'Ýatyr')}</AlertDialogCancel>
|
||||||
|
<AlertDialogAction
|
||||||
|
onClick={handleConfirmDelete}
|
||||||
|
className="bg-destructive text-destructive-foreground hover:bg-destructive/90"
|
||||||
|
>
|
||||||
|
{deletePermission.isPending
|
||||||
|
? t('common.deleting', 'Pozulýar...')
|
||||||
|
: t('common.delete', 'Poz')}
|
||||||
|
</AlertDialogAction>
|
||||||
|
</AlertDialogFooter>
|
||||||
|
</AlertDialogContent>
|
||||||
|
</AlertDialog>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -0,0 +1,194 @@
|
|||||||
|
import { useState } from 'react'
|
||||||
|
import { useNavigate } from 'react-router-dom'
|
||||||
|
import { useTranslation } from 'react-i18next'
|
||||||
|
import { Eye, Pencil, Trash2 } from 'lucide-react'
|
||||||
|
import type { ColumnDef, VisibilityState } from '@tanstack/react-table'
|
||||||
|
import { DataTable } from '@/components/dataTable'
|
||||||
|
import { DataTableToolbar } from '@/components/dataTableToolbar'
|
||||||
|
import { Button } from '@/components/ui/button'
|
||||||
|
import {
|
||||||
|
AlertDialog,
|
||||||
|
AlertDialogAction,
|
||||||
|
AlertDialogCancel,
|
||||||
|
AlertDialogContent,
|
||||||
|
AlertDialogDescription,
|
||||||
|
AlertDialogFooter,
|
||||||
|
AlertDialogHeader,
|
||||||
|
AlertDialogTitle,
|
||||||
|
} from '@/components/ui/alert-dialog'
|
||||||
|
import { useRoles, useDeleteRole } from '@/features/roles/hooks/useRoles'
|
||||||
|
import type { Role } from '@/features/roles/api/rolesApi'
|
||||||
|
|
||||||
|
// ─── Column meta for toolbar ──────────────────────────────────────────────────
|
||||||
|
|
||||||
|
const COLUMN_META = [
|
||||||
|
{ id: 'id', label: 'ID' },
|
||||||
|
{ id: 'code', label: 'Kod' },
|
||||||
|
{ id: 'name', label: 'Ady' },
|
||||||
|
{ id: 'guard_name', label: 'Guard name' },
|
||||||
|
]
|
||||||
|
|
||||||
|
// ─── RolesPage ────────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
|
export default function RolesPage() {
|
||||||
|
const { t } = useTranslation()
|
||||||
|
const navigate = useNavigate()
|
||||||
|
|
||||||
|
// ── State ──────────────────────────────────────────────────────────────────
|
||||||
|
const [search, setSearch] = useState('')
|
||||||
|
const [page, setPage] = useState(1)
|
||||||
|
const [perPage, setPerPage] = useState(25)
|
||||||
|
const [columnVisibility, setColumnVisibility] = useState<VisibilityState>({})
|
||||||
|
const [columnOrder, setColumnOrder] = useState<string[]>([])
|
||||||
|
const [deleteId, setDeleteId] = useState<number | null>(null)
|
||||||
|
|
||||||
|
// ── Data ───────────────────────────────────────────────────────────────────
|
||||||
|
const { data, isLoading } = useRoles({ search, page, per_page: perPage })
|
||||||
|
const deleteRole = useDeleteRole()
|
||||||
|
|
||||||
|
// ── Columns ────────────────────────────────────────────────────────────────
|
||||||
|
const columns: ColumnDef<Role>[] = [
|
||||||
|
{
|
||||||
|
accessorKey: 'id',
|
||||||
|
header: 'ID',
|
||||||
|
size: 70,
|
||||||
|
cell: ({ row }) => (
|
||||||
|
<span className="text-primary font-semibold">{row.original.id}</span>
|
||||||
|
),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
accessorKey: 'code',
|
||||||
|
header: t('roles.fields.code', 'Kod'),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
accessorKey: 'name',
|
||||||
|
header: t('roles.fields.name', 'Ady'),
|
||||||
|
cell: ({ row }) => <span>{row.original.name?.tk ?? '—'}</span>,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
accessorKey: 'guard_name',
|
||||||
|
header: 'Guard name',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 'actions',
|
||||||
|
header: '',
|
||||||
|
size: 120,
|
||||||
|
enableSorting: false,
|
||||||
|
enableHiding: false,
|
||||||
|
cell: ({ row }) => (
|
||||||
|
<div className="flex items-center justify-end gap-1">
|
||||||
|
<Button
|
||||||
|
variant="ghost"
|
||||||
|
size="icon"
|
||||||
|
className="h-8 w-8 text-muted-foreground hover:text-primary"
|
||||||
|
onClick={() => navigate(`/settings/users/roles/${row.original.id}`)}
|
||||||
|
>
|
||||||
|
<Eye size={15} />
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
variant="ghost"
|
||||||
|
size="icon"
|
||||||
|
className="h-8 w-8 text-muted-foreground hover:text-blue-500"
|
||||||
|
onClick={() => navigate(`/settings/users/roles/${row.original.id}/edit`)}
|
||||||
|
>
|
||||||
|
<Pencil size={15} />
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
variant="ghost"
|
||||||
|
size="icon"
|
||||||
|
className="h-8 w-8 text-muted-foreground hover:text-destructive"
|
||||||
|
onClick={() => setDeleteId(row.original.id)}
|
||||||
|
>
|
||||||
|
<Trash2 size={15} />
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
),
|
||||||
|
},
|
||||||
|
]
|
||||||
|
|
||||||
|
// ── Handlers ───────────────────────────────────────────────────────────────
|
||||||
|
const handleConfirmDelete = () => {
|
||||||
|
if (deleteId === null) return
|
||||||
|
deleteRole.mutate(deleteId, {
|
||||||
|
onSuccess: () => setDeleteId(null),
|
||||||
|
onError: () => setDeleteId(null),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// ── Render ─────────────────────────────────────────────────────────────────
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
{/* Page heading */}
|
||||||
|
<div className="flex items-center justify-between mb-6">
|
||||||
|
<h1 className="text-2xl font-bold text-foreground">
|
||||||
|
{t('roles.title', 'Rollar')}
|
||||||
|
</h1>
|
||||||
|
<Button onClick={() => navigate('/settings/users/roles/create')}>
|
||||||
|
{t('roles.actions.create', 'Rol dörediň')}
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Toolbar */}
|
||||||
|
<DataTableToolbar
|
||||||
|
searchValue={search}
|
||||||
|
onSearchChange={(v) => { setSearch(v); setPage(1) }}
|
||||||
|
searchPlaceholder={t('roles.searchPlaceholder', 'Gözlemek...')}
|
||||||
|
columns={COLUMN_META}
|
||||||
|
columnVisibility={columnVisibility}
|
||||||
|
onColumnVisibilityChange={setColumnVisibility}
|
||||||
|
columnOrder={columnOrder}
|
||||||
|
onColumnOrderChange={setColumnOrder}
|
||||||
|
perPageOptions={[10, 25, 50, 100]}
|
||||||
|
perPage={perPage}
|
||||||
|
onPerPageChange={(v) => { setPerPage(v); setPage(1) }}
|
||||||
|
/>
|
||||||
|
|
||||||
|
{/* Table */}
|
||||||
|
<DataTable
|
||||||
|
columns={columns}
|
||||||
|
data={data?.data ?? []}
|
||||||
|
isLoading={isLoading}
|
||||||
|
columnVisibility={columnVisibility}
|
||||||
|
onColumnVisibilityChange={setColumnVisibility}
|
||||||
|
columnOrder={columnOrder}
|
||||||
|
onColumnOrderChange={setColumnOrder}
|
||||||
|
getRowId={(row) => String(row.id)}
|
||||||
|
currentPage={data?.meta?.current_page ?? 1}
|
||||||
|
totalPages={data?.meta?.last_page ?? 1}
|
||||||
|
totalCount={data?.meta?.total ?? 0}
|
||||||
|
onPageChange={setPage}
|
||||||
|
/>
|
||||||
|
|
||||||
|
{/* Delete confirmation dialog */}
|
||||||
|
<AlertDialog
|
||||||
|
open={deleteId !== null}
|
||||||
|
onOpenChange={(open) => { if (!open) setDeleteId(null) }}
|
||||||
|
>
|
||||||
|
<AlertDialogContent>
|
||||||
|
<AlertDialogHeader>
|
||||||
|
<AlertDialogTitle>
|
||||||
|
{t('roles.deleteDialog.title', 'Roly pozmak')}
|
||||||
|
</AlertDialogTitle>
|
||||||
|
<AlertDialogDescription>
|
||||||
|
{t(
|
||||||
|
'roles.deleteDialog.description',
|
||||||
|
'Bu roly pozmak isleýärsiňizmi? Bu amal yzyna gaýtarylmaz.',
|
||||||
|
)}
|
||||||
|
</AlertDialogDescription>
|
||||||
|
</AlertDialogHeader>
|
||||||
|
<AlertDialogFooter>
|
||||||
|
<AlertDialogCancel>{t('common.cancel', 'Ýatyr')}</AlertDialogCancel>
|
||||||
|
<AlertDialogAction
|
||||||
|
onClick={handleConfirmDelete}
|
||||||
|
className="bg-destructive text-destructive-foreground hover:bg-destructive/90"
|
||||||
|
>
|
||||||
|
{deleteRole.isPending
|
||||||
|
? t('common.deleting', 'Pozulýar...')
|
||||||
|
: t('common.delete', 'Poz')}
|
||||||
|
</AlertDialogAction>
|
||||||
|
</AlertDialogFooter>
|
||||||
|
</AlertDialogContent>
|
||||||
|
</AlertDialog>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -0,0 +1,181 @@
|
|||||||
|
import { useState } from 'react'
|
||||||
|
import { useParams, useNavigate } from 'react-router-dom'
|
||||||
|
import { useTranslation } from 'react-i18next'
|
||||||
|
import { Pencil, Trash2 } from 'lucide-react'
|
||||||
|
import { Button } from '@/components/ui/button'
|
||||||
|
import {
|
||||||
|
AlertDialog,
|
||||||
|
AlertDialogAction,
|
||||||
|
AlertDialogCancel,
|
||||||
|
AlertDialogContent,
|
||||||
|
AlertDialogDescription,
|
||||||
|
AlertDialogFooter,
|
||||||
|
AlertDialogHeader,
|
||||||
|
AlertDialogTitle,
|
||||||
|
} from '@/components/ui/alert-dialog'
|
||||||
|
import { Skeleton } from '@/components/ui/skeleton'
|
||||||
|
import { Section, InfoRow } from '@/components/viewPageComponents'
|
||||||
|
import { useRole, useDeleteRole } from '@/features/roles/hooks/useRoles'
|
||||||
|
|
||||||
|
// ─── LangTabs ─────────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
|
type LangKey = 'tk' | 'ru' | 'en'
|
||||||
|
|
||||||
|
const LANG_TABS: { key: LangKey; label: string }[] = [
|
||||||
|
{ key: 'tk', label: 'Türkmen' },
|
||||||
|
{ key: 'ru', label: 'Русский' },
|
||||||
|
{ key: 'en', label: 'English' },
|
||||||
|
]
|
||||||
|
|
||||||
|
function LangTabs({
|
||||||
|
active,
|
||||||
|
onChange,
|
||||||
|
}: {
|
||||||
|
active: LangKey
|
||||||
|
onChange: (l: LangKey) => void
|
||||||
|
}) {
|
||||||
|
return (
|
||||||
|
<div className="flex gap-1 justify-end mb-2">
|
||||||
|
{LANG_TABS.map((tab) => (
|
||||||
|
<button
|
||||||
|
key={tab.key}
|
||||||
|
type="button"
|
||||||
|
onClick={() => onChange(tab.key)}
|
||||||
|
className={`px-3 py-0.5 text-xs font-medium rounded-md transition-colors ${
|
||||||
|
active === tab.key
|
||||||
|
? 'text-primary border-b-2 border-primary'
|
||||||
|
: 'text-muted-foreground hover:text-foreground'
|
||||||
|
}`}
|
||||||
|
>
|
||||||
|
{tab.label}
|
||||||
|
</button>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ─── RoleViewPage ─────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
|
export default function RoleViewPage() {
|
||||||
|
const { t } = useTranslation()
|
||||||
|
const { id } = useParams<{ id: string }>()
|
||||||
|
const navigate = useNavigate()
|
||||||
|
const roleId = Number(id)
|
||||||
|
|
||||||
|
const [activeLang, setActiveLang] = useState<LangKey>('tk')
|
||||||
|
const [showDelete, setShowDelete] = useState(false)
|
||||||
|
|
||||||
|
const { data: role, isLoading, isError } = useRole(roleId)
|
||||||
|
const deleteRole = useDeleteRole()
|
||||||
|
|
||||||
|
const handleConfirmDelete = () => {
|
||||||
|
deleteRole.mutate(roleId, {
|
||||||
|
onSuccess: () => navigate('/settings/users/roles'),
|
||||||
|
onError: () => setShowDelete(false),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// ── Loading skeleton ───────────────────────────────────────────────────────
|
||||||
|
if (isLoading) {
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
<Skeleton className="h-8 w-72 mb-6" />
|
||||||
|
<div className="bg-card border border-border rounded-xl overflow-hidden divide-y divide-border">
|
||||||
|
{Array.from({ length: 4 }).map((_, i) => (
|
||||||
|
<div key={i} className="grid grid-cols-[220px_1fr] items-center py-3 px-4">
|
||||||
|
<Skeleton className="h-4 w-20" />
|
||||||
|
<Skeleton className="h-4 w-40" />
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isError || !role) {
|
||||||
|
return (
|
||||||
|
<p className="text-destructive text-sm">
|
||||||
|
{t('common.fetchError', 'Maglumat ýüklenmedi.')}
|
||||||
|
</p>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ── Render ─────────────────────────────────────────────────────────────────
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
{/* Page heading + actions */}
|
||||||
|
<div className="flex items-start justify-between mb-6">
|
||||||
|
<h1 className="text-2xl font-bold text-foreground">
|
||||||
|
{t('roles.viewTitle', 'Rol giňişleýin')}: {role.name?.tk}
|
||||||
|
</h1>
|
||||||
|
<div className="flex items-center gap-2">
|
||||||
|
<Button
|
||||||
|
variant="outline"
|
||||||
|
size="icon"
|
||||||
|
className="text-muted-foreground hover:text-destructive hover:border-destructive"
|
||||||
|
onClick={() => setShowDelete(true)}
|
||||||
|
>
|
||||||
|
<Trash2 size={16} />
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
variant="outline"
|
||||||
|
size="icon"
|
||||||
|
className="text-muted-foreground hover:text-blue-500 hover:border-blue-500"
|
||||||
|
onClick={() => navigate(`/settings/users/roles/${roleId}/edit`)}
|
||||||
|
>
|
||||||
|
<Pencil size={16} />
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Detail section */}
|
||||||
|
<Section>
|
||||||
|
<InfoRow label="ID" value={role.id} />
|
||||||
|
<InfoRow label={t('roles.fields.code', 'Kod')} value={role.code} />
|
||||||
|
|
||||||
|
{/* Name row — with lang switcher */}
|
||||||
|
<div className="grid grid-cols-[220px_1fr] items-start py-2.5 px-4 border-b border-border">
|
||||||
|
<span className="text-sm text-muted-foreground pt-1">
|
||||||
|
{t('roles.fields.name', 'Ady')}
|
||||||
|
</span>
|
||||||
|
<div>
|
||||||
|
<LangTabs active={activeLang} onChange={setActiveLang} />
|
||||||
|
<span className="text-sm text-foreground">
|
||||||
|
{role.name?.[activeLang] || '—'}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<InfoRow label={t('roles.fields.guardName', 'Guard name')} value={role.guard_name} />
|
||||||
|
</Section>
|
||||||
|
|
||||||
|
{/* Delete dialog */}
|
||||||
|
<AlertDialog open={showDelete} onOpenChange={setShowDelete}>
|
||||||
|
<AlertDialogContent>
|
||||||
|
<AlertDialogHeader>
|
||||||
|
<AlertDialogTitle>
|
||||||
|
{t('roles.deleteDialog.title', 'Roly pozmak')}
|
||||||
|
</AlertDialogTitle>
|
||||||
|
<AlertDialogDescription>
|
||||||
|
{t(
|
||||||
|
'roles.deleteDialog.description',
|
||||||
|
'Bu roly pozmak isleýärsiňizmi? Bu amal yzyna gaýtarylmaz.',
|
||||||
|
)}
|
||||||
|
</AlertDialogDescription>
|
||||||
|
</AlertDialogHeader>
|
||||||
|
<AlertDialogFooter>
|
||||||
|
<AlertDialogCancel>{t('common.cancel', 'Ýatyr')}</AlertDialogCancel>
|
||||||
|
<AlertDialogAction
|
||||||
|
onClick={handleConfirmDelete}
|
||||||
|
className="bg-destructive text-destructive-foreground hover:bg-destructive/90"
|
||||||
|
>
|
||||||
|
{deleteRole.isPending
|
||||||
|
? t('common.deleting', 'Pozulýar...')
|
||||||
|
: t('common.delete', 'Poz')}
|
||||||
|
</AlertDialogAction>
|
||||||
|
</AlertDialogFooter>
|
||||||
|
</AlertDialogContent>
|
||||||
|
</AlertDialog>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -1,37 +1,14 @@
|
|||||||
import { useTranslation } from 'react-i18next'
|
import { useTranslation } from 'react-i18next'
|
||||||
import { useNavigate } from 'react-router-dom'
|
|
||||||
import { ChevronRight } from 'lucide-react'
|
|
||||||
import { UserForm } from '@/features/allUsers/components/allUsersForm'
|
import { UserForm } from '@/features/allUsers/components/allUsersForm'
|
||||||
|
|
||||||
// ─── UserCreatePage ───────────────────────────────────────────────────────────
|
// ─── UserCreatePage ───────────────────────────────────────────────────────────
|
||||||
|
|
||||||
export default function UserCreatePage() {
|
export default function UserCreatePage() {
|
||||||
const { t } = useTranslation()
|
const { t } = useTranslation()
|
||||||
const navigate = useNavigate()
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="p-6 space-y-4 max-w-4xl">
|
<div className="p-6 space-y-4 max-w-4xl">
|
||||||
{/* Breadcrumb */}
|
|
||||||
<nav className="flex items-center gap-1.5 text-xs text-muted-foreground">
|
|
||||||
<button
|
|
||||||
onClick={() => navigate('/users')}
|
|
||||||
className="hover:text-foreground transition-colors"
|
|
||||||
>
|
|
||||||
{t('nav.resources', 'Resurslar')}
|
|
||||||
</button>
|
|
||||||
<ChevronRight size={12} />
|
|
||||||
<button
|
|
||||||
onClick={() => navigate('/users')}
|
|
||||||
className="hover:text-foreground transition-colors"
|
|
||||||
>
|
|
||||||
{t('nav.users', 'Ulanyjylar')}
|
|
||||||
</button>
|
|
||||||
<ChevronRight size={12} />
|
|
||||||
<span className="text-foreground font-medium">
|
|
||||||
{t('users.actions.create', 'Ulanyjy dörediň')}
|
|
||||||
</span>
|
|
||||||
</nav>
|
|
||||||
|
|
||||||
{/* Title */}
|
{/* Title */}
|
||||||
<h1 className="text-2xl font-bold text-foreground">
|
<h1 className="text-2xl font-bold text-foreground">
|
||||||
{t('users.actions.create', 'Ulanyjy dörediň')}
|
{t('users.actions.create', 'Ulanyjy dörediň')}
|
||||||
|
|||||||
Reference in new issue
Block a user