Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.

255 righe
8.5 KiB

  1. import * as DateUtils from "utils/DateUtils"
  2. export const defaultHomePage = '/dashboard'
  3. // ** Checks if an object is empty (returns boolean)
  4. export const isObjEmpty = obj => {
  5. if (obj === null || obj === undefined) {
  6. return true
  7. }
  8. return Object.keys(obj).length === 0
  9. }
  10. // ** Returns K format from a number
  11. export const kFormatter = num => (num > 999 ? `${(num / 1000).toFixed(1)}k` : num)
  12. // ** Converts HTML to string
  13. export const htmlToString = html => html.replace(/<\/?[^>]+(>|$)/g, '')
  14. // ** Checks if the passed date is today
  15. const isToday = date => {
  16. const today = new Date()
  17. return (
  18. /* eslint-disable operator-linebreak */
  19. date.getDate() === today.getDate() &&
  20. date.getMonth() === today.getMonth() &&
  21. date.getFullYear() === today.getFullYear()
  22. /* eslint-enable */
  23. )
  24. }
  25. /**
  26. ** Format and return date in Humanize format
  27. ** Intl docs: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/format
  28. ** Intl Constructor: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/DateTimeFormat
  29. * @param {String} value date to format
  30. * @param {Object} formatting Intl object to format with
  31. */
  32. export const formatDate = (value, formatting = {month: 'short', day: 'numeric', year: 'numeric'}) => {
  33. if (!value) return value
  34. return new Intl.DateTimeFormat('en-US', formatting).format(new Date(value))
  35. }
  36. // ** Returns short month of passed date
  37. export const formatDateToMonthShort = (value, toTimeForCurrentDay = true) => {
  38. const date = new Date(value)
  39. let formatting = {month: 'short', day: 'numeric'}
  40. if (toTimeForCurrentDay && isToday(date)) {
  41. formatting = {hour: 'numeric', minute: 'numeric'}
  42. }
  43. return new Intl.DateTimeFormat('en-US', formatting).format(new Date(value))
  44. }
  45. /**
  46. ** Return if user is logged in
  47. ** This is completely up to you and how you want to store the token in your frontend application
  48. * ? e.g. If you are using cookies to store the application please update this function
  49. */
  50. export const isUserLoggedIn = () => localStorage.getItem('userData') != null
  51. export const getUserData = () => JSON.parse(localStorage.getItem('userData'))
  52. export const isAdminLoggedIn = () =>{
  53. if (localStorage.getItem('userData') != null){
  54. return JSON.parse(localStorage.getItem('userData')).role === 'admin'
  55. }
  56. }
  57. export const isGLDLoggedIn = () =>{
  58. if (localStorage.getItem('userData') != null){
  59. return JSON.parse(localStorage.getItem('userData')).type === 'GLD'
  60. }
  61. }
  62. export const isINDLoggedIn = () =>{
  63. if (localStorage.getItem('userData') != null){
  64. return JSON.parse(localStorage.getItem('userData')).type === 'IND'
  65. }
  66. }
  67. export const isORGLoggedIn = () =>{
  68. if (localStorage.getItem('userData') != null){
  69. return JSON.parse(localStorage.getItem('userData')).type === 'ORG'
  70. }
  71. }
  72. export const isPrimaryLoggedIn = () =>{
  73. if (localStorage.getItem('userData') != null){
  74. return JSON.parse(localStorage.getItem('userData')).role === 'primary'
  75. }
  76. }
  77. export const isCreditorLoggedIn = () =>{
  78. if (localStorage.getItem('userData') != null){
  79. return JSON.parse(localStorage.getItem('userData')).creditor
  80. }
  81. }
  82. export const isDummyLoggedIn = () =>{
  83. if (localStorage.getItem('userData') != null){
  84. return JSON.parse(localStorage.getItem('userData')).role === 'dummy'
  85. }
  86. }
  87. export const haveOrgPaymentRecord = () =>{
  88. if (localStorage.getItem('userData') != null){
  89. return JSON.parse(localStorage.getItem('userData')).orgPaymentRecord
  90. }
  91. }
  92. export const haveOrgDnRecord = () =>{
  93. if (localStorage.getItem('userData') != null){
  94. return JSON.parse(localStorage.getItem('userData')).orgDnRecord
  95. }
  96. }
  97. export const checkSysEnv = () =>{
  98. if (localStorage.getItem('sysEnv') != null){
  99. // console.log(localStorage.getItem('sysEnv'))
  100. return localStorage.getItem('sysEnv')
  101. }
  102. }
  103. export const checkPaymentSuspention = () =>{
  104. if (localStorage.getItem('paymentSuspention') != null){
  105. return JSON.parse(localStorage.getItem('paymentSuspention'))
  106. }
  107. }
  108. /**
  109. ** This function is used for demo purpose route navigation
  110. ** In real app you won't need this function because your app will navigate to same route for each users regardless of ability
  111. ** Please note role field is just for showing purpose it's not used by anything in frontend
  112. ** We are checking role just for ease
  113. * ? NOTE: If you have different pages to navigate based on user ability then this function can be useful. However, you need to update it.
  114. * @param {String} userRole Role of user
  115. */
  116. export const getHomeRouteForLoggedInUser = userRole => {
  117. if (userRole === 'admin') return defaultHomePage
  118. if (userRole === 'user') return defaultHomePage
  119. if (userRole === 'client') return '/access-control'
  120. return '/login'
  121. }
  122. // ** React Select Theme Colors
  123. export const selectThemeColors = theme => ({
  124. ...theme,
  125. colors: {
  126. ...theme.colors,
  127. primary25: '#7367f01a', // for option hover bg-color
  128. primary: '#7367f0', // for selected option bg-color
  129. neutral10: '#008a9a', // for tags bg-color
  130. neutral20: '#ededed', // for input border-color
  131. neutral30: '#ededed' // for input hover border-color
  132. }
  133. })
  134. export const momentMinuteDiff = (date1, date2) => {
  135. return moment.duration(moment(new Date(date1)).diff(moment(new Date(date2)))).asMinutes()
  136. }
  137. export const minuteDiff = (nowDate, createdAtDate) => {
  138. let diff = (nowDate.getTime() - new Date(createdAtDate)) / 1000
  139. diff /= 60
  140. return Math.abs(Math.ceil(diff))
  141. }
  142. export const gazetteLength = (length,noOfPages) => {
  143. let countLength=0;
  144. if (noOfPages!==null){
  145. let pages = noOfPages
  146. countLength = pages*18
  147. }else{
  148. countLength = length
  149. }
  150. return countLength+" cm"
  151. }
  152. export const getUserId = () =>{
  153. if (localStorage.getItem('userData') != null){
  154. return JSON.parse(localStorage.getItem('userData')).id
  155. }
  156. }
  157. export const isPasswordExpiry = () =>{
  158. var date;
  159. if (localStorage.getItem('userData') != null){
  160. date = JSON.parse(localStorage.getItem('userData')).passwordExpiryDate
  161. }
  162. if (date != null){
  163. var currentDate = new Date();
  164. var expirationDate = DateUtils.convertToDate(date);
  165. if (expirationDate < currentDate) {
  166. // console.log(true)
  167. return true; // The date has expired
  168. } else {
  169. // console.log(false)
  170. return false; // The date is still valid
  171. }
  172. }else{
  173. return false;
  174. }
  175. }
  176. export const checkIsOnlyOnlinePaymentByIssueDate = (date) => {
  177. // const targetDate = new Date(2025, 7, 1, 0, 0, 0) //2026-01-28T08:00:00.000Z hardcode
  178. const targetDate = new Date(2025, 11, 3, 0, 0, 0) //2026-01-28T08:00:00.000Z
  179. const checkDate = DateUtils.convertToDate(date)
  180. if (isDummyLoggedIn()){
  181. return false;
  182. }
  183. // console.log(checkDate)
  184. // console.log(targetDate)
  185. if (checkDate >= targetDate) {
  186. return true
  187. } else {
  188. return false;
  189. }
  190. }
  191. export const checkIsOnlyOnlinePayment = () => {
  192. // const targetDate = new Date(2025, 10, 17, 0, 0, 0) // hardcode
  193. const targetDate = new Date(2025, 11, 3, 0, 0, 0) // hardcode new Date(2026, 0, 28, 0, 0, 0) 28 Jan 2026
  194. const checkDate = DateUtils.convertToDate(new Date())
  195. if (isDummyLoggedIn()){
  196. return false;
  197. }
  198. // console.log(checkDate)
  199. // console.log(targetDate)
  200. if (checkDate >= targetDate) {
  201. return true
  202. } else {
  203. return false;
  204. }
  205. }
  206. export const checkMarkAsCreditClient = () => {
  207. // const targetDate = new Date(2025, 10, 17, 0, 0, 0) // hardcode
  208. const targetDate = new Date(2025, 11, 3, 0, 0, 0) // hardcode new Date(2026, 0, 28, 0, 0, 0) 28 Jan 2026
  209. const checkDate = DateUtils.convertToDate(new Date())
  210. // console.log(targetDate)
  211. // console.log(checkDate >= targetDate)
  212. if (checkDate >= targetDate) {
  213. return true
  214. } else {
  215. return false;
  216. }
  217. }
  218. export const checkIsNoPaymentByCreateDate = (date) => {
  219. // const targetDate = new Date(2025, 10, 18, 0, 0, 0) //2026-01-28T08:00:00.000Z hardcode
  220. const targetDate = new Date(2025, 11, 3, 0, 0, 0) //2026-01-28T08:00:00.000Z
  221. const checkDate = DateUtils.convertToDate(date)
  222. if (isDummyLoggedIn()){
  223. return false;
  224. }
  225. // console.log(checkDate)
  226. // console.log(targetDate)
  227. if (checkDate <= targetDate && isCreditorLoggedIn()) {
  228. return true
  229. } else {
  230. return false;
  231. }
  232. }