Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
S
sweepstake
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Arjun Jhukal
sweepstake
Commits
18ed2582
Commit
18ed2582
authored
Sep 23, 2025
by
Arjun Jhukal
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
updated the setting data populate issue
parent
8c75ba76
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
110 additions
and
47 deletions
+110
-47
InputFile.tsx
src/components/atom/InputFile.tsx
+23
-20
index.tsx
src/components/organism/Header/UserHeader/index.tsx
+12
-2
SiteSetting.tsx
...s/pages/dashboard/adminDashboard/settings/SiteSetting.tsx
+29
-13
setting.tsx
src/types/setting.tsx
+17
-2
checkAuth.ts
src/utils/checkAuth.ts
+29
-0
setActiveMenu.ts
src/utils/setActiveMenu.ts
+0
-10
No files found.
src/components/atom/InputFile.tsx
View file @
18ed2582
...
@@ -58,26 +58,29 @@ export default function InputFile({
...
@@ -58,26 +58,29 @@ export default function InputFile({
{
label
}
{
required
&&
<
span
className=
"text-red-500"
>
*
</
span
>
}
{
label
}
{
required
&&
<
span
className=
"text-red-500"
>
*
</
span
>
}
</
InputLabel
>
</
InputLabel
>
<
OutlinedInput
<
div
className=
"input_box relative"
>
fullWidth
<
OutlinedInput
id=
{
name
}
fullWidth
name=
{
name
}
id=
{
name
}
type=
"text"
name=
{
name
}
readOnly
type=
"text"
value=
{
readOnly
Array
.
isArray
(
value
)
// value={
?
value
.
map
((
f
)
=>
f
.
name
).
join
(
", "
)
||
""
// Array.isArray(value)
:
value
instanceof
File
// ? value.map((f) => f.name).join(", ") || ""
?
value
.
name
// : value instanceof File
:
""
// ? value.name
}
// : ""
placeholder=
"Choose file"
// }
onClick=
{
()
=>
document
.
getElementById
(
`${name}-file`
)?.
click
()
}
// placeholder="Choose file"
error=
{
Boolean
(
touched
&&
error
)
}
onClick=
{
()
=>
document
.
getElementById
(
`${name}-file`
)?.
click
()
}
sx=
{
{
error=
{
Boolean
(
touched
&&
error
)
}
cursor
:
"pointer"
,
sx=
{
{
}
}
cursor
:
"pointer"
,
/>
}
}
/>
<
span
className=
" absolute left-1 top-1/2 translate-y-[-50%] text-[11px] text-title bg-[#D8D8DD] inline-block py-1 px-2 z-[-1] rounded-sm"
>
Choose File
</
span
>
</
div
>
{
/* Hidden file input */
}
{
/* Hidden file input */
}
<
input
<
input
...
...
src/components/organism/Header/UserHeader/index.tsx
View file @
18ed2582
...
@@ -7,17 +7,27 @@ import GoldCoinIcon from '@/icons/GoldCoinIcon'
...
@@ -7,17 +7,27 @@ import GoldCoinIcon from '@/icons/GoldCoinIcon'
import
SilverCoinIcon
from
'@/icons/SilverCoinIcon'
import
SilverCoinIcon
from
'@/icons/SilverCoinIcon'
import
UserCoinCard
from
'./UserCoinCard'
import
UserCoinCard
from
'./UserCoinCard'
import
Private
from
'@/routes/Private'
import
Private
from
'@/routes/Private'
import
{
CheckAuth
}
from
'@/utils/checkAuth'
import
Link
from
'next/link'
import
{
PATH
}
from
'@/routes/PATH'
export
default
function
UserHeader
()
{
export
default
function
UserHeader
()
{
const
isAuth
=
CheckAuth
();
return
(
return
(
<
Box
className=
'flex items-center gap-4 justify-between w-full'
>
<
Box
className=
'flex items-center gap-4 justify-between w-full'
>
<
AdminSearchBar
/>
<
AdminSearchBar
/>
<
Private
>
{
isAuth
?
<
div
className=
"right flex items-center gap-4"
>
<
div
className=
"right flex items-center gap-4"
>
<
UserCoinCard
/>
<
UserCoinCard
/>
<
Profile
/>
<
Profile
/>
</
div
>
:
<
div
className=
"flex gap-3 items-center"
>
<
Link
href=
{
PATH
.
AUTH
.
REGISTER
.
ROOT
}
className=
'ss-btn bg-primary-grad text-nowrap'
>
Setup an account
</
Link
>
<
Link
href=
{
PATH
.
AUTH
.
LOGIN
.
ROOT
}
className=
'ss-btn bg-primary-grad'
>
Login
</
Link
>
</
div
>
</
div
>
</
Private
>
}
</
Box
>
</
Box
>
)
)
}
}
src/components/pages/dashboard/adminDashboard/settings/SiteSetting.tsx
View file @
18ed2582
...
@@ -9,26 +9,26 @@ import { CloseCircle } from "@wandersonalwes/iconsax-react";
...
@@ -9,26 +9,26 @@ import { CloseCircle } from "@wandersonalwes/iconsax-react";
import
{
useGetSettingsQuery
,
useUpdateSettingMutation
}
from
"@/services/settingApi"
;
import
{
useGetSettingsQuery
,
useUpdateSettingMutation
}
from
"@/services/settingApi"
;
import
{
useAppDispatch
}
from
"@/hooks/hook"
;
import
{
useAppDispatch
}
from
"@/hooks/hook"
;
import
{
showToast
,
ToastVariant
}
from
"@/slice/toastSlice"
;
import
{
showToast
,
ToastVariant
}
from
"@/slice/toastSlice"
;
import
{
SiteInitialRequest
}
from
"@/types/setting"
;
export
default
function
SiteSetting
()
{
export
default
function
SiteSetting
()
{
const
dispatch
=
useAppDispatch
();
const
dispatch
=
useAppDispatch
();
const
[
updateSetting
,
{
isLoading
}]
=
useUpdateSettingMutation
();
const
[
updateSetting
,
{
isLoading
}]
=
useUpdateSettingMutation
();
const
{
data
}
=
useGetSettingsQuery
();
const
{
data
}
=
useGetSettingsQuery
();
console
.
log
(
"settings"
,
data
);
const
formik
=
useFormik
({
const
formik
=
useFormik
({
initialValues
:
{
initialValues
:
data
?
{
site_name
:
data
?.
data
?.
site_name
,
favicon
:
null
,
favicon
:
null
,
logo
:
null
,
logo
:
null
,
site_name
:
""
,
unique_selling_points
:
data
?.
data
?.
unique_selling_points
.
map
((
usp
)
=>
({
unique_selling_points
:
[
title
:
usp
.
title
,
{
description
:
usp
.
description
,
title
:
""
,
icon
:
null
,
description
:
""
,
icon_url
:
usp
.
icon_url
icon
:
null
,
}))
},
}
:
SiteInitialRequest
,
],
enableReinitialize
:
true
,
},
validationSchema
:
Yup
.
object
({
validationSchema
:
Yup
.
object
({
favicon
:
Yup
.
mixed
().
required
(
"Favicon is required"
),
favicon
:
Yup
.
mixed
().
required
(
"Favicon is required"
),
logo
:
Yup
.
mixed
().
required
(
"Logo is required"
),
logo
:
Yup
.
mixed
().
required
(
"Logo is required"
),
...
@@ -42,21 +42,31 @@ export default function SiteSetting() {
...
@@ -42,21 +42,31 @@ export default function SiteSetting() {
),
),
}),
}),
onSubmit
:
async
(
values
)
=>
{
onSubmit
:
async
(
values
)
=>
{
const
formData
=
new
FormData
();
const
formData
=
new
FormData
();
if
(
values
.
favicon
)
formData
.
append
(
"favicon"
,
values
.
favicon
);
if
(
values
.
favicon
)
formData
.
append
(
"favicon"
,
values
.
favicon
);
if
(
values
.
logo
)
formData
.
append
(
"logo"
,
values
.
logo
);
if
(
values
.
logo
)
formData
.
append
(
"logo"
,
values
.
logo
);
// Append text fields
if
(
data
?.
data
?.
logo
)
{
formData
.
append
(
"logo_url"
,
data
.
data
.
logo
)
}
if
(
data
?.
data
?.
favicon
)
{
formData
.
append
(
"logo_url"
,
data
.
data
.
favicon
)
}
formData
.
append
(
"site_name"
,
values
.
site_name
);
formData
.
append
(
"site_name"
,
values
.
site_name
);
// Append USP data
values
.
unique_selling_points
.
forEach
((
usp
,
index
)
=>
{
values
.
unique_selling_points
.
forEach
((
usp
,
index
)
=>
{
formData
.
append
(
`unique_selling_points[
${
index
}
][title]`
,
usp
.
title
);
formData
.
append
(
`unique_selling_points[
${
index
}
][title]`
,
usp
.
title
);
formData
.
append
(
`unique_selling_points[
${
index
}
][description]`
,
usp
.
description
);
formData
.
append
(
`unique_selling_points[
${
index
}
][description]`
,
usp
.
description
);
if
(
usp
.
icon
)
{
if
(
usp
.
icon
)
{
formData
.
append
(
`unique_selling_points[
${
index
}
][icon]`
,
usp
.
icon
);
formData
.
append
(
`unique_selling_points[
${
index
}
][icon]`
,
usp
.
icon
);
}
}
if
(
usp
.
icon_url
)
{
formData
.
append
(
`unique_selling_points[
${
index
}
][icon_url]`
,
usp
.
icon_url
);
}
});
});
try
{
try
{
...
@@ -80,6 +90,8 @@ export default function SiteSetting() {
...
@@ -80,6 +90,8 @@ export default function SiteSetting() {
},
},
});
});
console
.
log
(
formik
.
values
,
data
?.
data
.
site_name
);
const
handleAddUSP
=
()
=>
{
const
handleAddUSP
=
()
=>
{
formik
.
setFieldValue
(
"unique_selling_points"
,
[
formik
.
setFieldValue
(
"unique_selling_points"
,
[
...
formik
.
values
.
unique_selling_points
,
...
formik
.
values
.
unique_selling_points
,
...
@@ -112,6 +124,7 @@ export default function SiteSetting() {
...
@@ -112,6 +124,7 @@ export default function SiteSetting() {
value=
{
formik
.
values
.
site_name
}
value=
{
formik
.
values
.
site_name
}
onChange=
{
formik
.
handleChange
}
onChange=
{
formik
.
handleChange
}
onBlur=
{
formik
.
handleBlur
}
onBlur=
{
formik
.
handleBlur
}
/>
/>
<
span
className=
"error"
>
<
span
className=
"error"
>
{
formik
.
touched
.
site_name
&&
formik
.
errors
.
site_name
{
formik
.
touched
.
site_name
&&
formik
.
errors
.
site_name
...
@@ -128,6 +141,7 @@ export default function SiteSetting() {
...
@@ -128,6 +141,7 @@ export default function SiteSetting() {
value=
{
formik
.
values
.
favicon
||
null
}
value=
{
formik
.
values
.
favicon
||
null
}
onChange=
{
(
file
:
File
|
File
[]
|
null
)
=>
formik
.
setFieldValue
(
"favicon"
,
file
)
}
onChange=
{
(
file
:
File
|
File
[]
|
null
)
=>
formik
.
setFieldValue
(
"favicon"
,
file
)
}
onBlur=
{
()
=>
formik
.
setFieldTouched
(
"favicon"
,
true
)
}
onBlur=
{
()
=>
formik
.
setFieldTouched
(
"favicon"
,
true
)
}
serverFile=
{
!
formik
.
values
.
favicon
?
data
?.
data
?.
favicon
:
""
}
/>
/>
<
span
className=
"error"
>
<
span
className=
"error"
>
{
formik
.
touched
.
favicon
&&
formik
.
errors
.
favicon
?
formik
.
errors
.
favicon
:
""
}
{
formik
.
touched
.
favicon
&&
formik
.
errors
.
favicon
?
formik
.
errors
.
favicon
:
""
}
...
@@ -142,6 +156,7 @@ export default function SiteSetting() {
...
@@ -142,6 +156,7 @@ export default function SiteSetting() {
value=
{
formik
.
values
.
logo
||
null
}
value=
{
formik
.
values
.
logo
||
null
}
onChange=
{
(
file
:
File
|
File
[]
|
null
)
=>
formik
.
setFieldValue
(
"logo"
,
file
)
}
onChange=
{
(
file
:
File
|
File
[]
|
null
)
=>
formik
.
setFieldValue
(
"logo"
,
file
)
}
onBlur=
{
()
=>
formik
.
setFieldTouched
(
"logo"
,
true
)
}
onBlur=
{
()
=>
formik
.
setFieldTouched
(
"logo"
,
true
)
}
serverFile=
{
!
formik
.
values
.
logo
?
data
?.
data
?.
logo
:
""
}
/>
/>
<
span
className=
"error"
>
<
span
className=
"error"
>
{
formik
.
touched
.
logo
&&
formik
.
errors
.
logo
?
formik
.
errors
.
logo
:
""
}
{
formik
.
touched
.
logo
&&
formik
.
errors
.
logo
?
formik
.
errors
.
logo
:
""
}
...
@@ -219,6 +234,7 @@ export default function SiteSetting() {
...
@@ -219,6 +234,7 @@ export default function SiteSetting() {
formik
.
setFieldValue
(
`unique_selling_points[${index}].icon`
,
file
)
formik
.
setFieldValue
(
`unique_selling_points[${index}].icon`
,
file
)
}
}
onBlur=
{
()
=>
formik
.
setFieldTouched
(
`unique_selling_points[${index}].icon`
,
true
)
}
onBlur=
{
()
=>
formik
.
setFieldTouched
(
`unique_selling_points[${index}].icon`
,
true
)
}
serverFile=
{
data
?.
data
?.
unique_selling_points
[
index
].
icon
}
/>
/>
<
span
className=
"error"
>
<
span
className=
"error"
>
{
formik
.
touched
.
unique_selling_points
?.[
index
]?.
icon
&&
{
formik
.
touched
.
unique_selling_points
?.[
index
]?.
icon
&&
...
...
src/types/setting.tsx
View file @
18ed2582
...
@@ -6,18 +6,33 @@ export interface SiteSettingRequestProps {
...
@@ -6,18 +6,33 @@ export interface SiteSettingRequestProps {
site_name
:
string
;
site_name
:
string
;
unique_selling_points
:
UspProps
[];
unique_selling_points
:
UspProps
[];
}
}
export
const
SiteInitialRequest
=
{
favicon
:
null
,
logo
:
null
,
site_name
:
""
,
unique_selling_points
:
[
{
title
:
""
,
description
:
""
,
icon
:
null
,
icon_url
:
""
},
],
}
export
interface
SiteSettingResponseProps
{
export
interface
SiteSettingResponseProps
{
success
:
string
;
success
:
string
;
message
:
string
;
message
:
string
;
data
:
{
data
:
{
fav
I
con
:
string
;
fav
i
con
:
string
;
logo
:
string
;
logo
:
string
;
site_name
:
string
;
site_name
:
string
;
unique_selling_points
:
{
unique_selling_points
:
{
title
:
string
;
title
:
string
;
description
:
string
;
description
:
string
;
icon
:
string
;
icon
:
string
;
}[]
icon_url
?:
string
;
}[];
}
}
}
}
...
...
src/utils/checkAuth.ts
0 → 100644
View file @
18ed2582
// utils/CheckAuth.ts
import
Cookies
from
"js-cookie"
;
import
{
cookies
as
nextCookies
}
from
"next/headers"
;
function
isTokenExpired
(
token
:
string
):
boolean
{
try
{
const
payload
=
JSON
.
parse
(
atob
(
token
.
split
(
"."
)[
1
]));
const
exp
=
payload
.
exp
;
if
(
!
exp
)
return
true
;
const
now
=
Math
.
floor
(
Date
.
now
()
/
1000
);
return
exp
<
now
;
}
catch
(
error
)
{
console
.
error
(
"Failed to decode token:"
,
error
);
return
true
;
}
}
export
function
CheckAuth
()
{
let
token
:
string
|
null
=
null
;
if
(
typeof
window
!==
"undefined"
)
{
token
=
localStorage
.
getItem
(
"access_token"
)
||
Cookies
.
get
(
"access_token"
)
||
null
;
}
if
(
!
token
)
return
false
;
if
(
isTokenExpired
(
token
))
return
false
;
return
true
;
}
src/utils/setActiveMenu.ts
deleted
100644 → 0
View file @
8c75ba76
export
function
setActiveMenu
(
pathname
:
string
,
paths
:
string
|
string
[]):
boolean
{
if
(
!
pathname
)
return
false
;
const
list
=
Array
.
isArray
(
paths
)
?
paths
:
[
paths
];
return
list
.
some
((
path
)
=>
{
const
normalized
=
path
.
startsWith
(
"/"
)
?
path
:
`/
${
path
}
`
;
return
pathname
.
startsWith
(
normalized
);
});
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment