← marzneshin
/
dashboard/src/modules/users/components/dialogs/mutation/sections/expiration-method/use-expiration-method-tabs.ts
/
blame
https://dev.kronoz.win/r/marzneshin.git
dashboard/src/modules/users/components/dialogs/mutation/sections/expiration-method/use-expiration-method-tabs.ts
· v0.7.2
Source
| 1 | e6e6467 | Dawsh | 2y ago | import { UserMutationType, ExpireStrategy } from "@marzneshin/modules/users"; |
| 2 | d377c4c | Dawsh | 2y ago | import { useState, useEffect } from "react"; |
| 3 | f035f9d | Mardin | 2y ago | import { useFormContext } from "react-hook-form"; |
| 4 | d377c4c | Dawsh | 2y ago | import { strategies } from "./expiration-method.strategy" |
| 5 | f035f9d | Mardin | 2y ago | |
| 6 | f035f9d | Mardin | 2y ago | |
| 7 | d42c6e6 | Mardin | 2y ago | export const useExpirationMethodTabs = (entity: UserMutationType | null) => { |
| 8 | f035f9d | Mardin | 2y ago | const form = useFormContext(); |
| 9 | f035f9d | Mardin | 2y ago | |
| 10 | d42c6e6 | Mardin | 2y ago | const [ |
| 11 | d42c6e6 | Mardin | 2y ago | selectedExpirationMethodTab, |
| 12 | d42c6e6 | Mardin | 2y ago | setSelectedExpirationMethodTab |
| 13 | d42c6e6 | Mardin | 2y ago | ] = useState<ExpireStrategy>(entity ? entity.expire_strategy : 'fixed_date'); |
| 14 | f035f9d | Mardin | 2y ago | useEffect(() => { |
| 15 | d377c4c | Dawsh | 2y ago | strategies[selectedExpirationMethodTab as ExpireStrategy].apply(form); |
| 16 | d377c4c | Dawsh | 2y ago | // eslint-disable-next-line react-hooks/exhaustive-deps |
| 17 | f035f9d | Mardin | 2y ago | }, [selectedExpirationMethodTab]); |
| 18 | f035f9d | Mardin | 2y ago | |
| 19 | d42c6e6 | Mardin | 2y ago | const handleTabChange = (value: string) => { |
| 20 | d42c6e6 | Mardin | 2y ago | setSelectedExpirationMethodTab(value as ExpireStrategy); |
| 21 | d42c6e6 | Mardin | 2y ago | }; |
| 22 | d42c6e6 | Mardin | 2y ago | |
| 23 | f035f9d | Mardin | 2y ago | return { |
| 24 | d42c6e6 | Mardin | 2y ago | selectedExpirationMethodTab, |
| 25 | d377c4c | Dawsh | 2y ago | setSelectedExpirationMethodTab, |
| 26 | d42c6e6 | Mardin | 2y ago | handleTabChange, |
| 27 | f035f9d | Mardin | 2y ago | }; |
| 28 | f035f9d | Mardin | 2y ago | }; |