diff --git a/.eslintrc.json b/.eslintrc.json index bffb357..121cefd 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -1,3 +1,3 @@ { - "extends": "next/core-web-vitals" + "extends": ["next/core-web-vitals","prettier"] } diff --git a/.prettierrc b/.prettierrc new file mode 100644 index 0000000..7eeebb6 --- /dev/null +++ b/.prettierrc @@ -0,0 +1,12 @@ +{ + "printWidth": 120, + "tabWidth": 4, + "useTabs": false, + "semi": true, + "singleQuote": false, + "trailingComma": "es5", + "bracketSpacing": true, + "jsxBracketSameLine": false, + "arrowParens": "always", + "endOfLine": "crlf" +} \ No newline at end of file diff --git a/editorconfig b/editorconfig deleted file mode 100644 index 05e5a39..0000000 --- a/editorconfig +++ /dev/null @@ -1,485 +0,0 @@ -root = true - -[*] -charset = utf-8 -end_of_line = crlf -indent_size = 4 -indent_style = space -insert_final_newline = false -max_line_length = 120 -tab_width = 4 -ij_continuation_indent_size = 4 -ij_formatter_off_tag = @formatter:off -ij_formatter_on_tag = @formatter:on -ij_formatter_tags_enabled = true -ij_smart_tabs = false -ij_visual_guides = none -ij_wrap_on_typing = false - -[*.css] -ij_css_align_closing_brace_with_properties = false -ij_css_blank_lines_around_nested_selector = 1 -ij_css_blank_lines_between_blocks = 1 -ij_css_block_comment_add_space = false -ij_css_brace_placement = end_of_line -ij_css_enforce_quotes_on_format = false -ij_css_hex_color_long_format = false -ij_css_hex_color_lower_case = false -ij_css_hex_color_short_format = false -ij_css_hex_color_upper_case = false -ij_css_keep_blank_lines_in_code = 2 -ij_css_keep_indents_on_empty_lines = false -ij_css_keep_single_line_blocks = false -ij_css_properties_order = font, font-family, font-size, font-weight, font-style, font-variant, font-size-adjust, font-stretch, line-height, position, z-index, top, right, bottom, left, display, visibility, float, clear, overflow, overflow-x, overflow-y, clip, zoom, align-content, align-items, align-self, flex, flex-flow, flex-basis, flex-direction, flex-grow, flex-shrink, flex-wrap, justify-content, order, box-sizing, width, min-width, max-width, height, min-height, max-height, margin, margin-top, margin-right, margin-bottom, margin-left, padding, padding-top, padding-right, padding-bottom, padding-left, table-layout, empty-cells, caption-side, border-spacing, border-collapse, list-style, list-style-position, list-style-type, list-style-image, content, quotes, counter-reset, counter-increment, resize, cursor, user-select, nav-index, nav-up, nav-right, nav-down, nav-left, transition, transition-delay, transition-timing-function, transition-duration, transition-property, transform, transform-origin, animation, animation-name, animation-duration, animation-play-state, animation-timing-function, animation-delay, animation-iteration-count, animation-direction, text-align, text-align-last, vertical-align, white-space, text-decoration, text-emphasis, text-emphasis-color, text-emphasis-style, text-emphasis-position, text-indent, text-justify, letter-spacing, word-spacing, text-outline, text-transform, text-wrap, text-overflow, text-overflow-ellipsis, text-overflow-mode, word-wrap, word-break, tab-size, hyphens, pointer-events, opacity, color, border, border-width, border-style, border-color, border-top, border-top-width, border-top-style, border-top-color, border-right, border-right-width, border-right-style, border-right-color, border-bottom, border-bottom-width, border-bottom-style, border-bottom-color, border-left, border-left-width, border-left-style, border-left-color, border-radius, border-top-left-radius, border-top-right-radius, border-bottom-right-radius, border-bottom-left-radius, border-image, border-image-source, border-image-slice, border-image-width, border-image-outset, border-image-repeat, outline, outline-width, outline-style, outline-color, outline-offset, background, background-color, background-image, background-repeat, background-attachment, background-position, background-position-x, background-position-y, background-clip, background-origin, background-size, box-decoration-break, box-shadow, text-shadow -ij_css_space_after_colon = true -ij_css_space_before_opening_brace = true -ij_css_use_double_quotes = true -ij_css_value_alignment = do_not_align - -[*.sass] -indent_size = 2 -ij_sass_align_closing_brace_with_properties = false -ij_sass_blank_lines_around_nested_selector = 1 -ij_sass_blank_lines_between_blocks = 1 -ij_sass_brace_placement = 0 -ij_sass_enforce_quotes_on_format = false -ij_sass_hex_color_long_format = false -ij_sass_hex_color_lower_case = false -ij_sass_hex_color_short_format = false -ij_sass_hex_color_upper_case = false -ij_sass_keep_blank_lines_in_code = 2 -ij_sass_keep_indents_on_empty_lines = false -ij_sass_keep_single_line_blocks = false -ij_sass_line_comment_add_space = false -ij_sass_line_comment_at_first_column = false -ij_sass_properties_order = font, font-family, font-size, font-weight, font-style, font-variant, font-size-adjust, font-stretch, line-height, position, z-index, top, right, bottom, left, display, visibility, float, clear, overflow, overflow-x, overflow-y, clip, zoom, align-content, align-items, align-self, flex, flex-flow, flex-basis, flex-direction, flex-grow, flex-shrink, flex-wrap, justify-content, order, box-sizing, width, min-width, max-width, height, min-height, max-height, margin, margin-top, margin-right, margin-bottom, margin-left, padding, padding-top, padding-right, padding-bottom, padding-left, table-layout, empty-cells, caption-side, border-spacing, border-collapse, list-style, list-style-position, list-style-type, list-style-image, content, quotes, counter-reset, counter-increment, resize, cursor, user-select, nav-index, nav-up, nav-right, nav-down, nav-left, transition, transition-delay, transition-timing-function, transition-duration, transition-property, transform, transform-origin, animation, animation-name, animation-duration, animation-play-state, animation-timing-function, animation-delay, animation-iteration-count, animation-direction, text-align, text-align-last, vertical-align, white-space, text-decoration, text-emphasis, text-emphasis-color, text-emphasis-style, text-emphasis-position, text-indent, text-justify, letter-spacing, word-spacing, text-outline, text-transform, text-wrap, text-overflow, text-overflow-ellipsis, text-overflow-mode, word-wrap, word-break, tab-size, hyphens, pointer-events, opacity, color, border, border-width, border-style, border-color, border-top, border-top-width, border-top-style, border-top-color, border-right, border-right-width, border-right-style, border-right-color, border-bottom, border-bottom-width, border-bottom-style, border-bottom-color, border-left, border-left-width, border-left-style, border-left-color, border-radius, border-top-left-radius, border-top-right-radius, border-bottom-right-radius, border-bottom-left-radius, border-image, border-image-source, border-image-slice, border-image-width, border-image-outset, border-image-repeat, outline, outline-width, outline-style, outline-color, outline-offset, background, background-color, background-image, background-repeat, background-attachment, background-position, background-position-x, background-position-y, background-clip, background-origin, background-size, box-decoration-break, box-shadow, text-shadow -ij_sass_space_after_colon = true -ij_sass_space_before_opening_brace = true -ij_sass_use_double_quotes = true -ij_sass_value_alignment = 0 - -[*.scss] -indent_size = 2 -ij_scss_align_closing_brace_with_properties = false -ij_scss_blank_lines_around_nested_selector = 1 -ij_scss_blank_lines_between_blocks = 1 -ij_scss_block_comment_add_space = false -ij_scss_brace_placement = 0 -ij_scss_enforce_quotes_on_format = false -ij_scss_hex_color_long_format = false -ij_scss_hex_color_lower_case = false -ij_scss_hex_color_short_format = false -ij_scss_hex_color_upper_case = false -ij_scss_keep_blank_lines_in_code = 2 -ij_scss_keep_indents_on_empty_lines = false -ij_scss_keep_single_line_blocks = false -ij_scss_line_comment_add_space = false -ij_scss_line_comment_at_first_column = false -ij_scss_properties_order = font, font-family, font-size, font-weight, font-style, font-variant, font-size-adjust, font-stretch, line-height, position, z-index, top, right, bottom, left, display, visibility, float, clear, overflow, overflow-x, overflow-y, clip, zoom, align-content, align-items, align-self, flex, flex-flow, flex-basis, flex-direction, flex-grow, flex-shrink, flex-wrap, justify-content, order, box-sizing, width, min-width, max-width, height, min-height, max-height, margin, margin-top, margin-right, margin-bottom, margin-left, padding, padding-top, padding-right, padding-bottom, padding-left, table-layout, empty-cells, caption-side, border-spacing, border-collapse, list-style, list-style-position, list-style-type, list-style-image, content, quotes, counter-reset, counter-increment, resize, cursor, user-select, nav-index, nav-up, nav-right, nav-down, nav-left, transition, transition-delay, transition-timing-function, transition-duration, transition-property, transform, transform-origin, animation, animation-name, animation-duration, animation-play-state, animation-timing-function, animation-delay, animation-iteration-count, animation-direction, text-align, text-align-last, vertical-align, white-space, text-decoration, text-emphasis, text-emphasis-color, text-emphasis-style, text-emphasis-position, text-indent, text-justify, letter-spacing, word-spacing, text-outline, text-transform, text-wrap, text-overflow, text-overflow-ellipsis, text-overflow-mode, word-wrap, word-break, tab-size, hyphens, pointer-events, opacity, color, border, border-width, border-style, border-color, border-top, border-top-width, border-top-style, border-top-color, border-right, border-right-width, border-right-style, border-right-color, border-bottom, border-bottom-width, border-bottom-style, border-bottom-color, border-left, border-left-width, border-left-style, border-left-color, border-radius, border-top-left-radius, border-top-right-radius, border-bottom-right-radius, border-bottom-left-radius, border-image, border-image-source, border-image-slice, border-image-width, border-image-outset, border-image-repeat, outline, outline-width, outline-style, outline-color, outline-offset, background, background-color, background-image, background-repeat, background-attachment, background-position, background-position-x, background-position-y, background-clip, background-origin, background-size, box-decoration-break, box-shadow, text-shadow -ij_scss_space_after_colon = true -ij_scss_space_before_opening_brace = true -ij_scss_use_double_quotes = true -ij_scss_value_alignment = 0 - -[{*.ats,*.cts,*.mts,*.ts}] -ij_continuation_indent_size = 4 -ij_typescript_align_imports = false -ij_typescript_align_multiline_array_initializer_expression = false -ij_typescript_align_multiline_binary_operation = false -ij_typescript_align_multiline_chained_methods = false -ij_typescript_align_multiline_extends_list = false -ij_typescript_align_multiline_for = true -ij_typescript_align_multiline_parameters = true -ij_typescript_align_multiline_parameters_in_calls = false -ij_typescript_align_multiline_ternary_operation = false -ij_typescript_align_object_properties = 0 -ij_typescript_align_union_types = false -ij_typescript_align_var_statements = 0 -ij_typescript_array_initializer_new_line_after_left_brace = false -ij_typescript_array_initializer_right_brace_on_new_line = false -ij_typescript_array_initializer_wrap = off -ij_typescript_assignment_wrap = off -ij_typescript_binary_operation_sign_on_next_line = false -ij_typescript_binary_operation_wrap = off -ij_typescript_blacklist_imports = rxjs/Rx, node_modules/**, **/node_modules/**, @angular/material, @angular/material/typings/** -ij_typescript_blank_lines_after_imports = 1 -ij_typescript_blank_lines_around_class = 1 -ij_typescript_blank_lines_around_field = 0 -ij_typescript_blank_lines_around_field_in_interface = 0 -ij_typescript_blank_lines_around_function = 1 -ij_typescript_blank_lines_around_method = 1 -ij_typescript_blank_lines_around_method_in_interface = 1 -ij_typescript_block_brace_style = end_of_line -ij_typescript_block_comment_add_space = false -ij_typescript_block_comment_at_first_column = true -ij_typescript_call_parameters_new_line_after_left_paren = false -ij_typescript_call_parameters_right_paren_on_new_line = false -ij_typescript_call_parameters_wrap = off -ij_typescript_catch_on_new_line = false -ij_typescript_chained_call_dot_on_new_line = true -ij_typescript_class_brace_style = end_of_line -ij_typescript_comma_on_new_line = false -ij_typescript_do_while_brace_force = never -ij_typescript_else_on_new_line = false -ij_typescript_enforce_trailing_comma = keep -ij_typescript_enum_constants_wrap = on_every_item -ij_typescript_extends_keyword_wrap = off -ij_typescript_extends_list_wrap = off -ij_typescript_field_prefix = _ -ij_typescript_file_name_style = relaxed -ij_typescript_finally_on_new_line = false -ij_typescript_for_brace_force = never -ij_typescript_for_statement_new_line_after_left_paren = false -ij_typescript_for_statement_right_paren_on_new_line = false -ij_typescript_for_statement_wrap = off -ij_typescript_force_quote_style = false -ij_typescript_force_semicolon_style = false -ij_typescript_function_expression_brace_style = end_of_line -ij_typescript_if_brace_force = never -ij_typescript_import_merge_members = global -ij_typescript_import_prefer_absolute_path = global -ij_typescript_import_sort_members = true -ij_typescript_import_sort_module_name = false -ij_typescript_import_use_node_resolution = true -ij_typescript_imports_wrap = on_every_item -ij_typescript_indent_case_from_switch = true -ij_typescript_indent_chained_calls = true -ij_typescript_indent_package_children = 0 -ij_typescript_jsdoc_include_types = false -ij_typescript_jsx_attribute_value = braces -ij_typescript_keep_blank_lines_in_code = 2 -ij_typescript_keep_first_column_comment = true -ij_typescript_keep_indents_on_empty_lines = false -ij_typescript_keep_line_breaks = true -ij_typescript_keep_simple_blocks_in_one_line = false -ij_typescript_keep_simple_methods_in_one_line = false -ij_typescript_line_comment_add_space = true -ij_typescript_line_comment_at_first_column = false -ij_typescript_method_brace_style = end_of_line -ij_typescript_method_call_chain_wrap = off -ij_typescript_method_parameters_new_line_after_left_paren = false -ij_typescript_method_parameters_right_paren_on_new_line = false -ij_typescript_method_parameters_wrap = off -ij_typescript_object_literal_wrap = on_every_item -ij_typescript_object_types_wrap = on_every_item -ij_typescript_parentheses_expression_new_line_after_left_paren = false -ij_typescript_parentheses_expression_right_paren_on_new_line = false -ij_typescript_place_assignment_sign_on_next_line = false -ij_typescript_prefer_as_type_cast = false -ij_typescript_prefer_explicit_types_function_expression_returns = false -ij_typescript_prefer_explicit_types_function_returns = false -ij_typescript_prefer_explicit_types_vars_fields = false -ij_typescript_prefer_parameters_wrap = false -ij_typescript_reformat_c_style_comments = false -ij_typescript_space_after_colon = true -ij_typescript_space_after_comma = true -ij_typescript_space_after_dots_in_rest_parameter = false -ij_typescript_space_after_generator_mult = true -ij_typescript_space_after_property_colon = true -ij_typescript_space_after_quest = true -ij_typescript_space_after_type_colon = true -ij_typescript_space_after_unary_not = false -ij_typescript_space_before_async_arrow_lparen = true -ij_typescript_space_before_catch_keyword = true -ij_typescript_space_before_catch_left_brace = true -ij_typescript_space_before_catch_parentheses = true -ij_typescript_space_before_class_lbrace = true -ij_typescript_space_before_class_left_brace = true -ij_typescript_space_before_colon = true -ij_typescript_space_before_comma = false -ij_typescript_space_before_do_left_brace = true -ij_typescript_space_before_else_keyword = true -ij_typescript_space_before_else_left_brace = true -ij_typescript_space_before_finally_keyword = true -ij_typescript_space_before_finally_left_brace = true -ij_typescript_space_before_for_left_brace = true -ij_typescript_space_before_for_parentheses = true -ij_typescript_space_before_for_semicolon = false -ij_typescript_space_before_function_left_parenth = true -ij_typescript_space_before_generator_mult = false -ij_typescript_space_before_if_left_brace = true -ij_typescript_space_before_if_parentheses = true -ij_typescript_space_before_method_call_parentheses = false -ij_typescript_space_before_method_left_brace = true -ij_typescript_space_before_method_parentheses = false -ij_typescript_space_before_property_colon = false -ij_typescript_space_before_quest = true -ij_typescript_space_before_switch_left_brace = true -ij_typescript_space_before_switch_parentheses = true -ij_typescript_space_before_try_left_brace = true -ij_typescript_space_before_type_colon = false -ij_typescript_space_before_unary_not = false -ij_typescript_space_before_while_keyword = true -ij_typescript_space_before_while_left_brace = true -ij_typescript_space_before_while_parentheses = true -ij_typescript_spaces_around_additive_operators = true -ij_typescript_spaces_around_arrow_function_operator = true -ij_typescript_spaces_around_assignment_operators = true -ij_typescript_spaces_around_bitwise_operators = true -ij_typescript_spaces_around_equality_operators = true -ij_typescript_spaces_around_logical_operators = true -ij_typescript_spaces_around_multiplicative_operators = true -ij_typescript_spaces_around_relational_operators = true -ij_typescript_spaces_around_shift_operators = true -ij_typescript_spaces_around_unary_operator = false -ij_typescript_spaces_within_array_initializer_brackets = false -ij_typescript_spaces_within_brackets = false -ij_typescript_spaces_within_catch_parentheses = false -ij_typescript_spaces_within_for_parentheses = false -ij_typescript_spaces_within_if_parentheses = false -ij_typescript_spaces_within_imports = false -ij_typescript_spaces_within_interpolation_expressions = false -ij_typescript_spaces_within_method_call_parentheses = false -ij_typescript_spaces_within_method_parentheses = false -ij_typescript_spaces_within_object_literal_braces = false -ij_typescript_spaces_within_object_type_braces = true -ij_typescript_spaces_within_parentheses = false -ij_typescript_spaces_within_switch_parentheses = false -ij_typescript_spaces_within_type_assertion = false -ij_typescript_spaces_within_union_types = true -ij_typescript_spaces_within_while_parentheses = false -ij_typescript_special_else_if_treatment = true -ij_typescript_ternary_operation_signs_on_next_line = false -ij_typescript_ternary_operation_wrap = off -ij_typescript_union_types_wrap = on_every_item -ij_typescript_use_chained_calls_group_indents = false -ij_typescript_use_double_quotes = true -ij_typescript_use_explicit_js_extension = auto -ij_typescript_use_path_mapping = always -ij_typescript_use_public_modifier = false -ij_typescript_use_semicolon_after_statement = true -ij_typescript_var_declaration_wrap = normal -ij_typescript_while_brace_force = never -ij_typescript_while_on_new_line = false -ij_typescript_wrap_comments = false - -[{*.cjs,*.js}] -ij_continuation_indent_size = 4 -ij_javascript_align_imports = false -ij_javascript_align_multiline_array_initializer_expression = false -ij_javascript_align_multiline_binary_operation = false -ij_javascript_align_multiline_chained_methods = false -ij_javascript_align_multiline_extends_list = false -ij_javascript_align_multiline_for = true -ij_javascript_align_multiline_parameters = true -ij_javascript_align_multiline_parameters_in_calls = false -ij_javascript_align_multiline_ternary_operation = false -ij_javascript_align_object_properties = 0 -ij_javascript_align_union_types = false -ij_javascript_align_var_statements = 0 -ij_javascript_array_initializer_new_line_after_left_brace = false -ij_javascript_array_initializer_right_brace_on_new_line = false -ij_javascript_array_initializer_wrap = off -ij_javascript_assignment_wrap = off -ij_javascript_binary_operation_sign_on_next_line = false -ij_javascript_binary_operation_wrap = off -ij_javascript_blacklist_imports = rxjs/Rx, node_modules/**, **/node_modules/**, @angular/material, @angular/material/typings/** -ij_javascript_blank_lines_after_imports = 1 -ij_javascript_blank_lines_around_class = 1 -ij_javascript_blank_lines_around_field = 0 -ij_javascript_blank_lines_around_function = 1 -ij_javascript_blank_lines_around_method = 1 -ij_javascript_block_brace_style = end_of_line -ij_javascript_block_comment_add_space = false -ij_javascript_block_comment_at_first_column = true -ij_javascript_call_parameters_new_line_after_left_paren = false -ij_javascript_call_parameters_right_paren_on_new_line = false -ij_javascript_call_parameters_wrap = off -ij_javascript_catch_on_new_line = false -ij_javascript_chained_call_dot_on_new_line = true -ij_javascript_class_brace_style = end_of_line -ij_javascript_comma_on_new_line = false -ij_javascript_do_while_brace_force = never -ij_javascript_else_on_new_line = false -ij_javascript_enforce_trailing_comma = keep -ij_javascript_extends_keyword_wrap = off -ij_javascript_extends_list_wrap = off -ij_javascript_field_prefix = _ -ij_javascript_file_name_style = relaxed -ij_javascript_finally_on_new_line = false -ij_javascript_for_brace_force = never -ij_javascript_for_statement_new_line_after_left_paren = false -ij_javascript_for_statement_right_paren_on_new_line = false -ij_javascript_for_statement_wrap = off -ij_javascript_force_quote_style = false -ij_javascript_force_semicolon_style = false -ij_javascript_function_expression_brace_style = end_of_line -ij_javascript_if_brace_force = never -ij_javascript_import_merge_members = global -ij_javascript_import_prefer_absolute_path = global -ij_javascript_import_sort_members = true -ij_javascript_import_sort_module_name = false -ij_javascript_import_use_node_resolution = true -ij_javascript_imports_wrap = on_every_item -ij_javascript_indent_case_from_switch = true -ij_javascript_indent_chained_calls = true -ij_javascript_indent_package_children = 0 -ij_javascript_jsx_attribute_value = braces -ij_javascript_keep_blank_lines_in_code = 2 -ij_javascript_keep_first_column_comment = true -ij_javascript_keep_indents_on_empty_lines = false -ij_javascript_keep_line_breaks = true -ij_javascript_keep_simple_blocks_in_one_line = false -ij_javascript_keep_simple_methods_in_one_line = false -ij_javascript_line_comment_add_space = true -ij_javascript_line_comment_at_first_column = false -ij_javascript_method_brace_style = end_of_line -ij_javascript_method_call_chain_wrap = off -ij_javascript_method_parameters_new_line_after_left_paren = false -ij_javascript_method_parameters_right_paren_on_new_line = false -ij_javascript_method_parameters_wrap = off -ij_javascript_object_literal_wrap = on_every_item -ij_javascript_object_types_wrap = on_every_item -ij_javascript_parentheses_expression_new_line_after_left_paren = false -ij_javascript_parentheses_expression_right_paren_on_new_line = false -ij_javascript_place_assignment_sign_on_next_line = false -ij_javascript_prefer_as_type_cast = false -ij_javascript_prefer_explicit_types_function_expression_returns = false -ij_javascript_prefer_explicit_types_function_returns = false -ij_javascript_prefer_explicit_types_vars_fields = false -ij_javascript_prefer_parameters_wrap = false -ij_javascript_reformat_c_style_comments = false -ij_javascript_space_after_colon = true -ij_javascript_space_after_comma = true -ij_javascript_space_after_dots_in_rest_parameter = false -ij_javascript_space_after_generator_mult = true -ij_javascript_space_after_property_colon = true -ij_javascript_space_after_quest = true -ij_javascript_space_after_type_colon = true -ij_javascript_space_after_unary_not = false -ij_javascript_space_before_async_arrow_lparen = true -ij_javascript_space_before_catch_keyword = true -ij_javascript_space_before_catch_left_brace = true -ij_javascript_space_before_catch_parentheses = true -ij_javascript_space_before_class_lbrace = true -ij_javascript_space_before_class_left_brace = true -ij_javascript_space_before_colon = true -ij_javascript_space_before_comma = false -ij_javascript_space_before_do_left_brace = true -ij_javascript_space_before_else_keyword = true -ij_javascript_space_before_else_left_brace = true -ij_javascript_space_before_finally_keyword = true -ij_javascript_space_before_finally_left_brace = true -ij_javascript_space_before_for_left_brace = true -ij_javascript_space_before_for_parentheses = true -ij_javascript_space_before_for_semicolon = false -ij_javascript_space_before_function_left_parenth = true -ij_javascript_space_before_generator_mult = false -ij_javascript_space_before_if_left_brace = true -ij_javascript_space_before_if_parentheses = true -ij_javascript_space_before_method_call_parentheses = false -ij_javascript_space_before_method_left_brace = true -ij_javascript_space_before_method_parentheses = false -ij_javascript_space_before_property_colon = false -ij_javascript_space_before_quest = true -ij_javascript_space_before_switch_left_brace = true -ij_javascript_space_before_switch_parentheses = true -ij_javascript_space_before_try_left_brace = true -ij_javascript_space_before_type_colon = false -ij_javascript_space_before_unary_not = false -ij_javascript_space_before_while_keyword = true -ij_javascript_space_before_while_left_brace = true -ij_javascript_space_before_while_parentheses = true -ij_javascript_spaces_around_additive_operators = true -ij_javascript_spaces_around_arrow_function_operator = true -ij_javascript_spaces_around_assignment_operators = true -ij_javascript_spaces_around_bitwise_operators = true -ij_javascript_spaces_around_equality_operators = true -ij_javascript_spaces_around_logical_operators = true -ij_javascript_spaces_around_multiplicative_operators = true -ij_javascript_spaces_around_relational_operators = true -ij_javascript_spaces_around_shift_operators = true -ij_javascript_spaces_around_unary_operator = false -ij_javascript_spaces_within_array_initializer_brackets = false -ij_javascript_spaces_within_brackets = false -ij_javascript_spaces_within_catch_parentheses = false -ij_javascript_spaces_within_for_parentheses = false -ij_javascript_spaces_within_if_parentheses = false -ij_javascript_spaces_within_imports = false -ij_javascript_spaces_within_interpolation_expressions = false -ij_javascript_spaces_within_method_call_parentheses = false -ij_javascript_spaces_within_method_parentheses = false -ij_javascript_spaces_within_object_literal_braces = false -ij_javascript_spaces_within_object_type_braces = true -ij_javascript_spaces_within_parentheses = false -ij_javascript_spaces_within_switch_parentheses = false -ij_javascript_spaces_within_type_assertion = false -ij_javascript_spaces_within_union_types = true -ij_javascript_spaces_within_while_parentheses = false -ij_javascript_special_else_if_treatment = true -ij_javascript_ternary_operation_signs_on_next_line = false -ij_javascript_ternary_operation_wrap = off -ij_javascript_union_types_wrap = on_every_item -ij_javascript_use_chained_calls_group_indents = false -ij_javascript_use_double_quotes = true -ij_javascript_use_explicit_js_extension = auto -ij_javascript_use_path_mapping = always -ij_javascript_use_public_modifier = false -ij_javascript_use_semicolon_after_statement = true -ij_javascript_var_declaration_wrap = normal -ij_javascript_while_brace_force = never -ij_javascript_while_on_new_line = false -ij_javascript_wrap_comments = false - -[{*.har,*.jsb2,*.jsb3,*.json,.babelrc,.eslintrc,.prettierrc,.stylelintrc,bowerrc,jest.config}] -indent_size = 2 -ij_json_array_wrapping = split_into_lines -ij_json_keep_blank_lines_in_code = 0 -ij_json_keep_indents_on_empty_lines = false -ij_json_keep_line_breaks = true -ij_json_keep_trailing_comma = false -ij_json_object_wrapping = split_into_lines -ij_json_property_alignment = do_not_align -ij_json_space_after_colon = true -ij_json_space_after_comma = true -ij_json_space_before_colon = false -ij_json_space_before_comma = false -ij_json_spaces_within_braces = false -ij_json_spaces_within_brackets = false -ij_json_wrap_long_lines = false - -[{*.htm,*.html,*.ng,*.sht,*.shtm,*.shtml}] -ij_html_add_new_line_before_tags = body, div, p, form, h1, h2, h3 -ij_html_align_attributes = true -ij_html_align_text = false -ij_html_attribute_wrap = normal -ij_html_block_comment_add_space = false -ij_html_block_comment_at_first_column = true -ij_html_do_not_align_children_of_min_lines = 0 -ij_html_do_not_break_if_inline_tags = title, h1, h2, h3, h4, h5, h6, p -ij_html_do_not_indent_children_of_tags = html, body, thead, tbody, tfoot -ij_html_enforce_quotes = false -ij_html_inline_tags = a, abbr, acronym, b, basefont, bdo, big, br, cite, cite, code, dfn, em, font, i, img, input, kbd, label, q, s, samp, select, small, span, strike, strong, sub, sup, textarea, tt, u, var -ij_html_keep_blank_lines = 2 -ij_html_keep_indents_on_empty_lines = false -ij_html_keep_line_breaks = true -ij_html_keep_line_breaks_in_text = true -ij_html_keep_whitespaces = false -ij_html_keep_whitespaces_inside = span, pre, textarea -ij_html_line_comment_at_first_column = true -ij_html_new_line_after_last_attribute = never -ij_html_new_line_before_first_attribute = never -ij_html_quote_style = double -ij_html_remove_new_line_before_tags = br -ij_html_space_after_tag_name = false -ij_html_space_around_equality_in_attribute = false -ij_html_space_inside_empty_tag = false -ij_html_text_wrap = normal - -[{*.markdown,*.md}] -ij_markdown_force_one_space_after_blockquote_symbol = true -ij_markdown_force_one_space_after_header_symbol = true -ij_markdown_force_one_space_after_list_bullet = true -ij_markdown_force_one_space_between_words = true -ij_markdown_format_tables = true -ij_markdown_insert_quote_arrows_on_wrap = true -ij_markdown_keep_indents_on_empty_lines = false -ij_markdown_keep_line_breaks_inside_text_blocks = true -ij_markdown_max_lines_around_block_elements = 1 -ij_markdown_max_lines_around_header = 1 -ij_markdown_max_lines_between_paragraphs = 1 -ij_markdown_min_lines_around_block_elements = 1 -ij_markdown_min_lines_around_header = 1 -ij_markdown_min_lines_between_paragraphs = 1 -ij_markdown_wrap_text_if_long = true -ij_markdown_wrap_text_inside_blockquotes = true diff --git a/package.json b/package.json index 4beef0b..b7f9320 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,8 @@ "dev": "next dev", "build": "next build", "start": "next start", - "lint": "next lint" + "lint": "next lint", + "format": "prettier --write \"src/**/*.{js,jsx,ts,tsx,html,css,scss}\"" }, "dependencies": { "@emotion/cache": "^11.11.0", @@ -35,6 +36,8 @@ }, "devDependencies": { "eslint": "^8", - "eslint-config-next": "14.1.0" + "eslint-config-next": "14.1.0", + "eslint-config-prettier": "^9.1.0", + "prettier": "^3.3.2" } } diff --git a/src/app/(withAuth)/dashboard/page.js b/src/app/(withAuth)/dashboard/page.js index 915b3de..c06d81d 100644 --- a/src/app/(withAuth)/dashboard/page.js +++ b/src/app/(withAuth)/dashboard/page.js @@ -1,29 +1,33 @@ -'use client' -import { Button } from "@mui/material" -import axios from "axios" +"use client"; +import { Button } from "@mui/material"; +import axios from "axios"; const Page = () => { const handler = () => { try { - axios.get('https://rms.witel.ir/test_login?username=witel', { withCredentials: true }) + axios.get("https://rms.witel.ir/test_login?username=witel", { + withCredentials: true, + }); } catch (error) { console.log(error); } - } + }; const handler2 = () => { try { - const res = axios.get('https://rms.witel.ir/webapi/user/get-permission', { withCredentials: true }) + const res = axios.get("https://rms.witel.ir/webapi/user/get-permission", { + withCredentials: true, + }); console.log(res); } catch (error) { console.log(error); } - } + }; return ( <> - ) -} + ); +}; -export default Page \ No newline at end of file +export default Page; diff --git a/src/app/(withAuth)/dashboard/template.js b/src/app/(withAuth)/dashboard/template.js index eb7d2ef..28b4ea0 100644 --- a/src/app/(withAuth)/dashboard/template.js +++ b/src/app/(withAuth)/dashboard/template.js @@ -1,19 +1,17 @@ import { Box, Stack } from "@mui/material"; import HeaderWithLogo from "@/components/layouts/dashboard/headerWithLogo"; import HeaderWithSidebar from "@/components/layouts/dashboard/headerWithSidebar"; -import 'react-toastify/dist/ReactToastify.css'; +import "react-toastify/dist/ReactToastify.css"; const Template = ({ children }) => { return ( - - {children} - + {children} - ) -} + ); +}; -export default Template \ No newline at end of file +export default Template; diff --git a/src/app/(withAuth)/layout.js b/src/app/(withAuth)/layout.js index 5a5cca8..400bbc9 100644 --- a/src/app/(withAuth)/layout.js +++ b/src/app/(withAuth)/layout.js @@ -1,14 +1,12 @@ -import WithAuthMiddleware from "@/core/middlewares/withAuth" -import { AuthProvider } from "@/lib/contexts/auth" +import WithAuthMiddleware from "@/core/middlewares/withAuth"; +import { AuthProvider } from "@/lib/contexts/auth"; const Layout = ({ children }) => { return ( - - {children} - + {children} - ) -} + ); +}; -export default Layout \ No newline at end of file +export default Layout; diff --git a/src/app/default.js b/src/app/default.js index 73d13c1..d157a71 100644 --- a/src/app/default.js +++ b/src/app/default.js @@ -1,3 +1,3 @@ export default function Default() { - return null -} \ No newline at end of file + return null; +} diff --git a/src/app/layout.js b/src/app/layout.js index 1d4819e..64aea89 100644 --- a/src/app/layout.js +++ b/src/app/layout.js @@ -1,17 +1,15 @@ import { TableSettingProvider } from "@/lib/contexts/tableSetting"; export const metadata = { - title: 'سامانه جامع راهداری', -} + title: "سامانه جامع راهداری", +}; export default function RootLayout({ children }) { return ( - - - - {children} - + + + {children} - ) + ); } diff --git a/src/app/lfwd/page.js b/src/app/lfwd/page.js index 55eca31..b3456a3 100644 --- a/src/app/lfwd/page.js +++ b/src/app/lfwd/page.js @@ -1,51 +1,57 @@ -'use client' +"use client"; -import { GET_LOGIN_ROUTE } from "@/core/utils/routes" -import useRequest from "@/lib/hooks/useRequest" -import { Button, Stack, Typography, Zoom } from "@mui/material" -import Link from "next/link" -import { useEffect, useState } from "react" +import { GET_LOGIN_ROUTE } from "@/core/utils/routes"; +import useRequest from "@/lib/hooks/useRequest"; +import { Button, Stack, Typography, Zoom } from "@mui/material"; +import Link from "next/link"; +import { useEffect, useState } from "react"; -const Page = () => { - const [login, setLogin] = useState(0) - const request = useRequest() +const Page = ({ searchParams }) => { + const { username } = searchParams; + const [login, setLogin] = useState(0); + const request = useRequest(); useEffect(() => { const login = async () => { try { - const res = await request(`${GET_LOGIN_ROUTE}?username=witel`) - setLogin(1) + await request(`${GET_LOGIN_ROUTE}?username=${username}`); + setLogin(1); } catch (error) { - setLogin(2) + setLogin(2); } - } + }; - login() - }, []) + login(); + }, []); const retry = async () => { - setLogin(0) + setLogin(0); try { - const res = await request(`${GET_LOGIN_ROUTE}?username=witel`) - setLogin(1) + await request(`${GET_LOGIN_ROUTE}?username=${username}`); + setLogin(1); } catch (error) { - setLogin(2) + setLogin(2); } - } - + }; return ( - + - {login === 0 ? 'درحال دریافت مجوز برای ارتباط با سرور...' : login === 1 ? 'ارتباط با سرور برقرار شد.' : 'ارتباط با سرور برقرار نشد. مشکلی وجود دارد.'} + {login === 0 + ? "درحال دریافت مجوز برای ارتباط با سرور..." + : login === 1 + ? "ارتباط با سرور برقرار شد." + : "ارتباط با سرور برقرار نشد. مشکلی وجود دارد."} - + - ) -} -export default Page \ No newline at end of file + ); +}; +export default Page; diff --git a/src/app/page.js b/src/app/page.js index 3fab3b7..2997c35 100644 --- a/src/app/page.js +++ b/src/app/page.js @@ -1,8 +1,8 @@ -import { redirect } from "next/navigation" +import { redirect } from "next/navigation"; function Page() { - redirect('/dashboard', 'replace') - return null + redirect("/dashboard", "replace"); + return null; } -export default Page \ No newline at end of file +export default Page; diff --git a/src/app/template.js b/src/app/template.js index 71830af..3ffc656 100644 --- a/src/app/template.js +++ b/src/app/template.js @@ -15,7 +15,7 @@ const Template = ({ children }) => { - ) -} + ); +}; -export default Template \ No newline at end of file +export default Template; diff --git a/src/components/home/Toolbar.jsx b/src/components/home/Toolbar.jsx index 1270b92..82f2646 100644 --- a/src/components/home/Toolbar.jsx +++ b/src/components/home/Toolbar.jsx @@ -1,22 +1,10 @@ -import {Button} from "@mui/material"; +import { Button } from "@mui/material"; -const Toolbar = ({columns}) => { +const Toolbar = ({ columns }) => { return ( <> - ) -} -export default Toolbar - - - - - - - - - - - - + ); +}; +export default Toolbar; diff --git a/src/components/home/index.jsx b/src/components/home/index.jsx index 090a572..7344232 100644 --- a/src/components/home/index.jsx +++ b/src/components/home/index.jsx @@ -1,149 +1,128 @@ -'use client' +"use client"; import DataTable from "@/core/components/DataTable"; -import {useMemo} from "react"; +import { useMemo } from "react"; function HomeComponent() { const columns = useMemo( () => [ { - accessorKey: 'fullname', - header: 'نام کامل', + accessorKey: "fullname", + header: "نام کامل", id: "fullname", columns: [ { - accessorKey: 'name.firstName', - header: 'نام', + accessorKey: "name.firstName", + header: "نام", id: "firstName", enableColumnFilter: true, datatype: "text", filterFn: "contains", enableClickToCopy: true, - columnFilterModeOptions: [ - "equals", - "notEquals", - "contains" - ], + columnFilterModeOptions: ["equals", "notEquals", "contains"], }, { - accessorKey: 'name.lastName', - header: 'نام خانوادگی', + accessorKey: "name.lastName", + header: "نام خانوادگی", id: "lastName", enableColumnFilter: true, datatype: "text", filterFn: "equals", - columnFilterModeOptions: [ - "equals", - "notEquals", - "contains" - ], + columnFilterModeOptions: ["equals", "notEquals", "contains"], }, ], }, { - accessorKey: 'address', - header: 'آدرس', + accessorKey: "address", + header: "آدرس", id: "address", enableColumnFilter: true, datatype: "text", filterFn: "notEquals", - columnFilterModeOptions: [ - "equals", - "notEquals", - "contains" - ], + columnFilterModeOptions: ["equals", "notEquals", "contains"], }, { - accessorKey: 'city', - header: 'شهر', + accessorKey: "city", + header: "شهر", id: "city", enableColumnFilter: true, datatype: "text", filterFn: "equals", - columnFilterModeOptions: [ - "equals", - "notEquals", - "contains", - "lessThan", - "greaterThan", - "fuzzy" - ], + columnFilterModeOptions: ["equals", "notEquals", "contains", "lessThan", "greaterThan", "fuzzy"], }, { - accessorKey: 'state', - header: 'وضعیت', + accessorKey: "state", + header: "وضعیت", id: "state", enableColumnFilter: true, datatype: "text", filterFn: "contains", - columnFilterModeOptions: [ - "equals", - "notEquals", - "contains" - ], + columnFilterModeOptions: ["equals", "notEquals", "contains"], }, { - accessorKey: 'price', - header: 'محدوده', + accessorKey: "price", + header: "محدوده", id: "price", enableColumnFilter: true, datatype: "numeric", filterFn: "equals", - columnFilterModeOptions: [ - "equals", - "notEquals", - ], + columnFilterModeOptions: ["equals", "notEquals"], }, { - accessorKey: 'created_at', - header: 'تاریخ ساخت', + accessorKey: "created_at", + header: "تاریخ ساخت", id: "created_at", enableColumnFilter: true, datatype: "date", filterFn: "between", }, { - accessorKey: 'updated_at', - header: 'تاریخ بروزرسانی', + accessorKey: "updated_at", + header: "تاریخ بروزرسانی", id: "updated_at", enableColumnFilter: true, datatype: "date", filterFn: "equals", }, { - accessorKey: 'company', - header: 'نام شرکت', + accessorKey: "company", + header: "نام شرکت", id: "company", enableColumnFilter: true, datatype: "numeric", filterFn: "equals", columnSelectOption: [ - {value: 1, label: "وایتل"}, - {value: 2, label: "اسنپ"}, - {value: 3, label: "تپسی"} + { value: 1, label: "وایتل" }, + { value: 2, label: "اسنپ" }, + { value: 3, label: "تپسی" }, ], }, { - accessorKey: 'area', - header: 'منطقه', + accessorKey: "area", + header: "منطقه", id: "area", enableColumnFilter: true, datatype: "array", filterFn: "equals", columnSelectOption: [ - {value: 1, label: "وایتل"}, - {value: 2, label: "اسنپ"}, - {value: 3, label: "تپسی"} + { value: 1, label: "وایتل" }, + { value: 2, label: "اسنپ" }, + { value: 3, label: "تپسی" }, ], }, ], - [], + [] ); return ( <> - + - ); } diff --git a/src/components/layouts/dashboard/headerWithLogo/HaederBottom/index.jsx b/src/components/layouts/dashboard/headerWithLogo/HaederBottom/index.jsx index 501dadc..62ec234 100644 --- a/src/components/layouts/dashboard/headerWithLogo/HaederBottom/index.jsx +++ b/src/components/layouts/dashboard/headerWithLogo/HaederBottom/index.jsx @@ -3,38 +3,25 @@ import { Stack, Typography } from "@mui/material"; import Image from "next/image"; const HeaderBottom = () => { - return ( - theme.palette.primary2.main, - }} - spacing={4} - alignItems={"center"} - direction={"row"} - > - - - theme.palette.primary2.contrastText }} + return ( + theme.palette.primary2.main, + }} + spacing={4} + alignItems={"center"} + direction={"row"} > - سامانه جامع راهداری - - theme.palette.primary2.contrastText }} - > - rms.rmto.ir - - - - ); + + + theme.palette.primary2.contrastText }}> + سامانه جامع راهداری + + theme.palette.primary2.contrastText }}>rms.rmto.ir + + + ); }; export default HeaderBottom; diff --git a/src/components/layouts/dashboard/headerWithLogo/HaederTop/index.jsx b/src/components/layouts/dashboard/headerWithLogo/HaederTop/index.jsx index 27cd26a..6899881 100644 --- a/src/components/layouts/dashboard/headerWithLogo/HaederTop/index.jsx +++ b/src/components/layouts/dashboard/headerWithLogo/HaederTop/index.jsx @@ -2,16 +2,10 @@ import { Stack } from "@mui/material"; import Image from "next/image"; const HeaderTop = () => { - return ( - - - - ); + return ( + + + + ); }; export default HeaderTop; diff --git a/src/components/layouts/dashboard/headerWithLogo/index.jsx b/src/components/layouts/dashboard/headerWithLogo/index.jsx index f628e49..16ef4b2 100644 --- a/src/components/layouts/dashboard/headerWithLogo/index.jsx +++ b/src/components/layouts/dashboard/headerWithLogo/index.jsx @@ -3,11 +3,11 @@ import HeaderTop from "./HaederTop"; import HeaderBottom from "./HaederBottom"; const HeaderWithLogo = () => { - return ( - - - - - ); + return ( + + + + + ); }; export default HeaderWithLogo; diff --git a/src/components/layouts/dashboard/headerWithSidebar/HeaderMenu/index.jsx b/src/components/layouts/dashboard/headerWithSidebar/HeaderMenu/index.jsx index 01fd681..c705242 100644 --- a/src/components/layouts/dashboard/headerWithSidebar/HeaderMenu/index.jsx +++ b/src/components/layouts/dashboard/headerWithSidebar/HeaderMenu/index.jsx @@ -1,4 +1,4 @@ const HeaderMenu = () => { - return <>منو; + return <>منو; }; export default HeaderMenu; diff --git a/src/components/layouts/dashboard/headerWithSidebar/index.jsx b/src/components/layouts/dashboard/headerWithSidebar/index.jsx index be0a284..c8febb6 100644 --- a/src/components/layouts/dashboard/headerWithSidebar/index.jsx +++ b/src/components/layouts/dashboard/headerWithSidebar/index.jsx @@ -9,108 +9,102 @@ import HeaderMenu from "./HeaderMenu"; const drawerWidth = 300; -const Main = styled(Paper, { shouldForwardProp: (prop) => prop !== "open" })( - ({ theme, open }) => ({ +const Main = styled(Paper, { shouldForwardProp: (prop) => prop !== "open" })(({ theme, open }) => ({ flexGrow: 1, transition: theme.transitions.create("margin", { - easing: theme.transitions.easing.sharp, - duration: theme.transitions.duration.leavingScreen, + easing: theme.transitions.easing.sharp, + duration: theme.transitions.duration.leavingScreen, }), marginLeft: `-${drawerWidth}px`, ...(open && { - transition: theme.transitions.create("margin", { - easing: theme.transitions.easing.easeOut, - duration: theme.transitions.duration.enteringScreen, - }), - marginLeft: 0, + transition: theme.transitions.create("margin", { + easing: theme.transitions.easing.easeOut, + duration: theme.transitions.duration.enteringScreen, + }), + marginLeft: 0, }), - }) -); +})); const AppBar = styled(MuiAppBar, { - shouldForwardProp: (prop) => prop !== "open", + shouldForwardProp: (prop) => prop !== "open", })(({ theme, open }) => ({ - transition: theme.transitions.create(["margin", "width"], { - easing: theme.transitions.easing.sharp, - duration: theme.transitions.duration.leavingScreen, - }), - ...(open && { - width: `calc(100% - ${drawerWidth}px)`, - marginLeft: `${drawerWidth}px`, transition: theme.transitions.create(["margin", "width"], { - easing: theme.transitions.easing.easeOut, - duration: theme.transitions.duration.enteringScreen, + easing: theme.transitions.easing.sharp, + duration: theme.transitions.duration.leavingScreen, + }), + ...(open && { + width: `calc(100% - ${drawerWidth}px)`, + marginLeft: `${drawerWidth}px`, + transition: theme.transitions.create(["margin", "width"], { + easing: theme.transitions.easing.easeOut, + duration: theme.transitions.duration.enteringScreen, + }), }), - }), })); const DrawerHeader = styled("div")(({ theme }) => ({ - display: "flex", - alignItems: "center", - padding: theme.spacing(0, 1), - ...theme.mixins.toolbar, - justifyContent: "flex-end", + display: "flex", + alignItems: "center", + padding: theme.spacing(0, 1), + ...theme.mixins.toolbar, + justifyContent: "flex-end", })); const HeaderWithSidebar = ({ children }) => { - const [open, setOpen] = useState(true); + const [open, setOpen] = useState(true); - const handleDrawerOpen = () => { - setOpen(true); - }; - const handleDrawerClose = () => { - setOpen(false); - }; - return ( - - - - - - - - - - - - - - - - - - - -
- - {children} -
-
- ); + const handleDrawerOpen = () => { + setOpen(true); + }; + const handleDrawerClose = () => { + setOpen(false); + }; + return ( + + + + + + + + + + + + + + + + + + + +
+ + {children} +
+
+ ); }; export default HeaderWithSidebar; diff --git a/src/core/components/DataTable/Main.js b/src/core/components/DataTable/Main.js index ec33f55..db8aebd 100644 --- a/src/core/components/DataTable/Main.js +++ b/src/core/components/DataTable/Main.js @@ -1,91 +1,96 @@ import DataTable_Paper from "./table/Paper"; -import {useMaterialReactTable} from "material-react-table"; -import {FA_DATATABLE_LOCALIZATION} from "./localization/fa/datatable"; +import { useMaterialReactTable } from "material-react-table"; +import { FA_DATATABLE_LOCALIZATION } from "./localization/fa/datatable"; import useTableSetting from "@/lib/hooks/useTableSetting"; -import {flattenArrayOfObjects} from "@/core/utils/flattenArrayOfObjects"; +import { flattenArrayOfObjects } from "@/core/utils/flattenArrayOfObjects"; import Toolbar from "@/components/home/Toolbar"; import useDataTable from "@/lib/hooks/useDataTable"; -import {useMemo, useState} from "react"; +import { useMemo, useState } from "react"; const data = [ { name: { - firstName: 'امین', - lastName: 'قاسمپور', + firstName: "امین", + lastName: "قاسمپور", }, - address: 'فلان جا', - city: 'تهران', - state: 'بررسی شده', - price: '20', - updated_at: '2024/05/02', - company: 'همراه اول', - area: 'منطقه 5', + address: "فلان جا", + city: "تهران", + state: "بررسی شده", + price: "20", + updated_at: "2024/05/02", + company: "همراه اول", + area: "منطقه 5", }, { name: { - firstName: 'امیر حسین', - lastName: 'محمودی', + firstName: "امیر حسین", + lastName: "محمودی", }, - address: 'فلان جا', - city: 'تهران', - state: 'تکمیل شده', - price: '27', - updated_at: '2024/05/02', - company: 'وایتل', - area: 'منطقه 27', + address: "فلان جا", + city: "تهران", + state: "تکمیل شده", + price: "27", + updated_at: "2024/05/02", + company: "وایتل", + area: "منطقه 27", }, { name: { - firstName: 'یاسمن', - lastName: 'علی اکبری', + firstName: "یاسمن", + lastName: "علی اکبری", }, - address: 'فلان جا', - city: 'شیراز', - state: 'بررسی شده', - price: '32', - updated_at: '2024/05/02', - company: 'ایرانسل', - area: 'منطقه 23', + address: "فلان جا", + city: "شیراز", + state: "بررسی شده", + price: "32", + updated_at: "2024/05/02", + company: "ایرانسل", + area: "منطقه 23", }, { name: { - firstName: 'حمیدرضا', - lastName: 'رنجبرپور', + firstName: "حمیدرضا", + lastName: "رنجبرپور", }, - address: 'فلان جا', - city: 'اصفهان', - state: 'بررسی شده', - price: '45', - updated_at: '2024/05/02', - company: 'ایرانول', - area: 'منطقه 21', + address: "فلان جا", + city: "اصفهان", + state: "بررسی شده", + price: "45", + updated_at: "2024/05/02", + company: "ایرانول", + area: "منطقه 21", }, { name: { - firstName: 'محمد', - lastName: 'جلالی', + firstName: "محمد", + lastName: "جلالی", }, - address: 'فلان جا', - city: 'رشت', - state: 'درحال بررسی', - price: '8', - updated_at: '2024/05/02', - company: 'فیلیمو', - area: 'منطقه 8', + address: "فلان جا", + city: "رشت", + state: "درحال بررسی", + price: "8", + updated_at: "2024/05/02", + company: "فیلیمو", + area: "منطقه 8", }, ]; const DataTable_Main = (props) => { - const {filterData} = useDataTable(); - const {table_url, user_id, page_name, table_name, columns, initialStateProps} = props - const flatColumns = flattenArrayOfObjects(columns, 'columns') - const {settingStore, hideAction, sortAction} = useTableSetting(); - const [pagination, setPagination] = useState({pageIndex: 0, pageSize: 10}); + const { filterData } = useDataTable(); + const { table_url, user_id, page_name, table_name, columns, initialStateProps } = props; + const flatColumns = flattenArrayOfObjects(columns, "columns"); + const { settingStore, hideAction, sortAction } = useTableSetting(); + const [pagination, setPagination] = useState({ pageIndex: 0, pageSize: 10 }); const filters = Object.keys(filterData) - .map(key => { + .map((key) => { const value = filterData[key].value; - if (value !== "" && - !(Array.isArray(value) && (value.length === 0 || (value.length === 2 && value[0] === "" && value[1] === "")))) { + if ( + value !== "" && + !( + Array.isArray(value) && + (value.length === 0 || (value.length === 2 && value[0] === "" && value[1] === "")) + ) + ) { return filterData[key]; } }) @@ -98,7 +103,7 @@ const DataTable_Main = (props) => { params.set("start", `${pagination.pageIndex * pagination.pageSize}`); params.set("size", pagination.pageSize); params.set("filters", JSON.stringify(finalFilters ?? [])); - params.set("sorting", JSON.stringify(settingStore?.[user_id]?.[page_name]?.[table_name]?.['sorts'] ?? [])); + params.set("sorting", JSON.stringify(settingStore?.[user_id]?.[page_name]?.[table_name]?.["sorts"] ?? [])); return `${table_url}?${params}`; }, [table_url, finalFilters, pagination, columns]); @@ -107,52 +112,52 @@ const DataTable_Main = (props) => { hideAction(user_id, page_name, table_name, settingValue, flatColumns); }; const onSortingChange = (event) => { - const settingValue = event(settingStore?.[user_id]?.[page_name]?.[table_name]?.['sorts'] || []); + const settingValue = event(settingStore?.[user_id]?.[page_name]?.[table_name]?.["sorts"] || []); sortAction(user_id, page_name, table_name, settingValue, flatColumns); - } + }; const table = useMaterialReactTable({ localization: FA_DATATABLE_LOCALIZATION, columns, data: data, // manualSorting: true, - renderTopToolbarCustomActions: ({table}) => (<> - - ), + renderTopToolbarCustomActions: ({ table }) => ( + <> + + + ), initialState: { - density: 'compact', - columnVisibility: settingStore?.[user_id]?.[page_name]?.[table_name]?.['hides'], - sorting: settingStore?.[user_id]?.[page_name]?.[table_name]?.['sorts'] || [], - ...initialStateProps + density: "compact", + columnVisibility: settingStore?.[user_id]?.[page_name]?.[table_name]?.["hides"], + sorting: settingStore?.[user_id]?.[page_name]?.[table_name]?.["sorts"] || [], + ...initialStateProps, }, state: { - columnVisibility: settingStore?.[user_id]?.[page_name]?.[table_name]?.['hides'], - sorting: settingStore?.[user_id]?.[page_name]?.[table_name]?.['sorts'] || [], - pagination + columnVisibility: settingStore?.[user_id]?.[page_name]?.[table_name]?.["hides"], + sorting: settingStore?.[user_id]?.[page_name]?.[table_name]?.["sorts"] || [], + pagination, }, muiTableHeadProps: { sx: { borderTop: "1px solid #e1e1e1", borderBottom: "2px solid #e1e1e1", - } + }, }, muiTableHeadCellProps: { sx: { color: "primary.main", borderLeft: "1px solid #e1e1e1", "&:first-of-type": { - borderLeft: "unset" - } + borderLeft: "unset", + }, }, }, muiTableBodyCellProps: { sx: { borderLeft: "1px solid #e1e1e1", "&:first-of-type": { - borderLeft: "unset" - } + borderLeft: "unset", + }, }, }, manualFiltering: true, @@ -161,14 +166,18 @@ const DataTable_Main = (props) => { manualSorting: true, onColumnVisibilityChange: onColumnVisibilityChange, onSortingChange: onSortingChange, - ...props - }) + ...props, + }); - return ; + return ( + + ); }; export default DataTable_Main; - - - diff --git a/src/core/components/DataTable/body/TableBody.js b/src/core/components/DataTable/body/TableBody.js index e1620a3..b0750be 100644 --- a/src/core/components/DataTable/body/TableBody.js +++ b/src/core/components/DataTable/body/TableBody.js @@ -4,11 +4,7 @@ import { useMRT_RowVirtualizer, useMRT_Rows } from "material-react-table"; import { memo, useMemo } from "react"; import DataTable_TableBodyRow, { Memo_DataTable_TableBodyRow } from "./TableBodyRow"; -const DataTable_TableBody = ({ - columnVirtualizer, - table, - ...rest -}) => { +const DataTable_TableBody = ({ columnVirtualizer, table, ...rest }) => { const { getBottomRows, getIsSomeRowsPinned, @@ -35,12 +31,8 @@ const DataTable_TableBody = ({ ...rest, }; - const tableHeadHeight = - ((enableStickyHeader || isFullScreen) && - tableHeadRef.current?.clientHeight) || - 0; - const tableFooterHeight = - (enableStickyFooter && tableFooterRef.current?.clientHeight) || 0; + const tableHeadHeight = ((enableStickyHeader || isFullScreen) && tableHeadRef.current?.clientHeight) || 0; + const tableFooterHeight = (enableStickyFooter && tableFooterRef.current?.clientHeight) || 0; const pinnedRowIds = useMemo(() => { if (!rowPinning.bottom?.length && !rowPinning.top?.length) return []; @@ -63,67 +55,63 @@ const DataTable_TableBody = ({ return ( <> - {!rowPinningDisplayMode?.includes('sticky') && - getIsSomeRowsPinned('top') && ( - ({ - display: layoutMode?.startsWith('grid') ? 'grid' : undefined, - position: 'sticky', - top: tableHeadHeight - 1, - zIndex: 1, - ...(parseFromValuesOrFunc(tableBodyProps?.sx, theme)), - })} - > - {getTopRows().map((row, staticRowIndex) => { - const props = { - ...commonRowProps, - row, - staticRowIndex, - }; - return memoMode === 'rows' ? ( - - ) : ( - - ); - })} - - )} + {!rowPinningDisplayMode?.includes("sticky") && getIsSomeRowsPinned("top") && ( + ({ + display: layoutMode?.startsWith("grid") ? "grid" : undefined, + position: "sticky", + top: tableHeadHeight - 1, + zIndex: 1, + ...parseFromValuesOrFunc(tableBodyProps?.sx, theme), + })} + > + {getTopRows().map((row, staticRowIndex) => { + const props = { + ...commonRowProps, + row, + staticRowIndex, + }; + return memoMode === "rows" ? ( + + ) : ( + + ); + })} + + )} ({ - display: layoutMode?.startsWith('grid') ? 'grid' : undefined, - height: rowVirtualizer - ? `${rowVirtualizer.getTotalSize()}px` - : undefined, - minHeight: !rows.length ? '100px' : undefined, - position: 'relative', - ...(parseFromValuesOrFunc(tableBodyProps?.sx, theme)), + display: layoutMode?.startsWith("grid") ? "grid" : undefined, + height: rowVirtualizer ? `${rowVirtualizer.getTotalSize()}px` : undefined, + minHeight: !rows.length ? "100px" : undefined, + position: "relative", + ...parseFromValuesOrFunc(tableBodyProps?.sx, theme), })} > {tableBodyProps?.children ?? (!rows.length ? ( {renderEmptyRowsFallback?.({ table }) ?? ( {globalFilter || columnFilters.length @@ -155,12 +143,10 @@ const DataTable_TableBody = ({ row, rowVirtualizer, staticRowIndex, - virtualRow: rowVirtualizer - ? (rowOrVirtualRow) - : undefined, + virtualRow: rowVirtualizer ? rowOrVirtualRow : undefined, }; const key = `${row.id}-${row.index}`; - return memoMode === 'rows' ? ( + return memoMode === "rows" ? ( ) : ( @@ -169,39 +155,37 @@ const DataTable_TableBody = ({ ))} - {!rowPinningDisplayMode?.includes('sticky') && - getIsSomeRowsPinned('bottom') && ( - ({ - bottom: tableFooterHeight - 1, - display: layoutMode?.startsWith('grid') ? 'grid' : undefined, - position: 'sticky', - zIndex: 1, - ...(parseFromValuesOrFunc(tableBodyProps?.sx, theme)), - })} - > - {getBottomRows().map((row, staticRowIndex) => { - const props = { - ...commonRowProps, - row, - staticRowIndex, - }; - return memoMode === 'rows' ? ( - - ) : ( - - ); - })} - - )} + {!rowPinningDisplayMode?.includes("sticky") && getIsSomeRowsPinned("bottom") && ( + ({ + bottom: tableFooterHeight - 1, + display: layoutMode?.startsWith("grid") ? "grid" : undefined, + position: "sticky", + zIndex: 1, + ...parseFromValuesOrFunc(tableBodyProps?.sx, theme), + })} + > + {getBottomRows().map((row, staticRowIndex) => { + const props = { + ...commonRowProps, + row, + staticRowIndex, + }; + return memoMode === "rows" ? ( + + ) : ( + + ); + })} + + )} ); - -} -export default DataTable_TableBody +}; +export default DataTable_TableBody; export const Memo_DataTable_TableBody = memo( DataTable_TableBody, - (prev, next) => prev.table.options.data === next.table.options.data, -); \ No newline at end of file + (prev, next) => prev.table.options.data === next.table.options.data +); diff --git a/src/core/components/DataTable/body/TableBodyCell.js b/src/core/components/DataTable/body/TableBodyCell.js index 9ef022d..4c1804b 100644 --- a/src/core/components/DataTable/body/TableBodyCell.js +++ b/src/core/components/DataTable/body/TableBodyCell.js @@ -7,15 +7,7 @@ const { useState, useEffect, useMemo, memo } = require("react"); const { default: DataTable_CopyButton } = require("../buttons/CopyButton"); const { default: DataTable_TableBodyCellValue } = require("./TableBodyCellValue"); -const DataTable_TableBodyCell = ({ - cell, - numRows, - rowRef, - staticColumnIndex, - staticRowIndex, - table, - ...rest -}) => { +const DataTable_TableBodyCell = ({ cell, numRows, rowRef, staticColumnIndex, staticRowIndex, table, ...rest }) => { const theme = useTheme(); const { getState, @@ -73,9 +65,7 @@ const DataTable_TableBodyCell = ({ if ((!isLoading && !showSkeletons) || skeletonWidth !== 100) return; const size = column.getSize(); setSkeletonWidth( - columnDefType === 'display' - ? size / 2 - : Math.round(Math.random() * (size - size / 3) + size / 3), + columnDefType === "display" ? size / 2 : Math.round(Math.random() * (size - size / 3) + size / 3) ); }, [isLoading, showSkeletons]); @@ -88,77 +78,55 @@ const DataTable_TableBodyCell = ({ const isLastColumn = column.getIsLastColumn(); const isLastRow = numRows && staticRowIndex === numRows - 1; const isResizingColumn = columnSizingInfo.isResizingColumn === column.id; - const showResizeBorder = - isResizingColumn && columnResizeMode === 'onChange'; + const showResizeBorder = isResizingColumn && columnResizeMode === "onChange"; const borderStyle = showResizeBorder ? `2px solid ${draggingBorderColor} !important` : isDraggingColumn || isDraggingRow - ? `1px dashed ${theme.palette.grey[500]} !important` - : isHoveredColumn || isHoveredRow || isResizingColumn - ? `2px dashed ${draggingBorderColor} !important` - : undefined; + ? `1px dashed ${theme.palette.grey[500]} !important` + : isHoveredColumn || isHoveredRow || isResizingColumn + ? `2px dashed ${draggingBorderColor} !important` + : undefined; if (showResizeBorder) { - return columnResizeDirection === 'ltr' - ? { borderRight: borderStyle } - : { borderLeft: borderStyle }; + return columnResizeDirection === "ltr" ? { borderRight: borderStyle } : { borderLeft: borderStyle }; } return borderStyle ? { - borderBottom: - isDraggingRow || isHoveredRow || (isLastRow && !isResizingColumn) - ? borderStyle - : undefined, - borderLeft: - isDraggingColumn || - isHoveredColumn || - ((isDraggingRow || isHoveredRow) && isFirstColumn) - ? borderStyle - : undefined, - borderRight: - isDraggingColumn || - isHoveredColumn || - ((isDraggingRow || isHoveredRow) && isLastColumn) - ? borderStyle - : undefined, - borderTop: isDraggingRow || isHoveredRow ? borderStyle : undefined, - } + borderBottom: + isDraggingRow || isHoveredRow || (isLastRow && !isResizingColumn) ? borderStyle : undefined, + borderLeft: + isDraggingColumn || isHoveredColumn || ((isDraggingRow || isHoveredRow) && isFirstColumn) + ? borderStyle + : undefined, + borderRight: + isDraggingColumn || isHoveredColumn || ((isDraggingRow || isHoveredRow) && isLastColumn) + ? borderStyle + : undefined, + borderTop: isDraggingRow || isHoveredRow ? borderStyle : undefined, + } : undefined; - }, [ - columnSizingInfo.isResizingColumn, - draggingColumn, - draggingRow, - hoveredColumn, - hoveredRow, - staticRowIndex, - ]); + }, [columnSizingInfo.isResizingColumn, draggingColumn, draggingRow, hoveredColumn, hoveredRow, staticRowIndex]); - const isColumnPinned = - enableColumnPinning && - columnDef.columnDefType !== 'group' && - column.getIsPinned(); + const isColumnPinned = enableColumnPinning && columnDef.columnDefType !== "group" && column.getIsPinned(); const isEditable = isCellEditable({ cell, table }); const isEditing = isEditable && - !['custom', 'modal'].includes(editDisplayMode) && - (editDisplayMode === 'table' || - editingRow?.id === row.id || - editingCell?.id === cell.id) && + !["custom", "modal"].includes(editDisplayMode) && + (editDisplayMode === "table" || editingRow?.id === row.id || editingCell?.id === cell.id) && !row.getIsGrouped(); - const isCreating = - isEditable && createDisplayMode === 'row' && creatingRow?.id === row.id; + const isCreating = isEditable && createDisplayMode === "row" && creatingRow?.id === row.id; const showClickToCopyButton = (parseFromValuesOrFunc(enableClickToCopy, cell) === true || parseFromValuesOrFunc(columnDef.enableClickToCopy, cell) === true) && - !['context-menu', false].includes( + !["context-menu", false].includes( // @ts-ignore - parseFromValuesOrFunc(columnDef.enableClickToCopy, cell), + parseFromValuesOrFunc(columnDef.enableClickToCopy, cell) ); const isRightClickable = parseFromValuesOrFunc(enableCellActions, cell); @@ -175,13 +143,11 @@ const DataTable_TableBodyCell = ({ const handleDragEnter = (e) => { tableCellProps?.onDragEnter?.(e); - if (enableGrouping && hoveredColumn?.id === 'drop-zone') { + if (enableGrouping && hoveredColumn?.id === "drop-zone") { setHoveredColumn(null); } if (enableColumnOrdering && draggingColumn) { - setHoveredColumn( - columnDef.enableColumnOrdering !== false ? column : null, - ); + setHoveredColumn(columnDef.enableColumnOrdering !== false ? column : null); } }; @@ -210,43 +176,39 @@ const DataTable_TableBodyCell = ({ onDragEnter={handleDragEnter} onDragOver={handleDragOver} sx={(theme) => ({ - '&:hover': { + "&:hover": { outline: actionCell?.id === cell.id || - (editDisplayMode === 'cell' && isEditable) || - (editDisplayMode === 'table' && (isCreating || isEditing)) + (editDisplayMode === "cell" && isEditable) || + (editDisplayMode === "table" && (isCreating || isEditing)) ? `1px solid ${theme.palette.grey[500]}` : undefined, - textOverflow: 'clip', + textOverflow: "clip", }, - alignItems: layoutMode?.startsWith('grid') ? 'center' : undefined, + alignItems: layoutMode?.startsWith("grid") ? "center" : undefined, cursor: isRightClickable - ? 'context-menu' - : isEditable && editDisplayMode === 'cell' - ? 'pointer' - : 'inherit', - outline: - actionCell?.id === cell.id - ? `1px solid ${theme.palette.grey[500]}` - : undefined, - outlineOffset: '-1px', - overflow: 'hidden', + ? "context-menu" + : isEditable && editDisplayMode === "cell" + ? "pointer" + : "inherit", + outline: actionCell?.id === cell.id ? `1px solid ${theme.palette.grey[500]}` : undefined, + outlineOffset: "-1px", + overflow: "hidden", p: - density === 'compact' - ? columnDefType === 'display' - ? '0 0.5rem' - : '0.5rem' - : density === 'comfortable' - ? columnDefType === 'display' - ? '0.5rem 0.75rem' - : '1rem' - : columnDefType === 'display' - ? '1rem 1.25rem' - : '1.5rem', + density === "compact" + ? columnDefType === "display" + ? "0 0.5rem" + : "0.5rem" + : density === "comfortable" + ? columnDefType === "display" + ? "0.5rem 0.75rem" + : "1rem" + : columnDefType === "display" + ? "1rem 1.25rem" + : "1.5rem", - textOverflow: columnDefType !== 'display' ? 'ellipsis' : undefined, - whiteSpace: - row.getIsPinned() || density === 'compact' ? 'nowrap' : 'normal', + textOverflow: columnDefType !== "display" ? "ellipsis" : undefined, + whiteSpace: row.getIsPinned() || density === "compact" ? "nowrap" : "normal", ...getCommonMRTCellStyles({ column, table, @@ -261,17 +223,10 @@ const DataTable_TableBodyCell = ({ {cell.getIsPlaceholder() ? ( columnDef.PlaceholderCell?.({ cell, column, row, table }) ?? null ) : showSkeletons !== false && (isLoading || showSkeletons) ? ( - - ) : columnDefType === 'display' && - (['mrt-row-expand', 'mrt-row-numbers', 'mrt-row-select'].includes( - column.id, - ) || - !row.getIsGrouped()) ? ( + + ) : columnDefType === "display" && + (["mrt-row-expand", "mrt-row-numbers", "mrt-row-select"].includes(column.id) || + !row.getIsGrouped()) ? ( columnDef.Cell?.({ cell, column, @@ -289,18 +244,12 @@ const DataTable_TableBodyCell = ({ ) : ( )} - {cell.getIsGrouped() && !columnDef.GroupedCell && ( - <> ({row.subRows?.length}) - )} + {cell.getIsGrouped() && !columnDef.GroupedCell && <> ({row.subRows?.length})} )} ); - -} +}; export default DataTable_TableBodyCell; -export const Memo_DataTable_TableBodyCell = memo( - DataTable_TableBodyCell, - (prev, next) => next.cell === prev.cell, -); \ No newline at end of file +export const Memo_DataTable_TableBodyCell = memo(DataTable_TableBodyCell, (prev, next) => next.cell === prev.cell); diff --git a/src/core/components/DataTable/body/TableBodyCellValue.js b/src/core/components/DataTable/body/TableBodyCellValue.js index 6d4f05f..aea105f 100644 --- a/src/core/components/DataTable/body/TableBodyCellValue.js +++ b/src/core/components/DataTable/body/TableBodyCellValue.js @@ -2,111 +2,102 @@ import { Box } from "@mui/material"; const allowedTypes = ["string", "number"]; -const DataTable_TableBodyCellValue = ({ - cell, - rowRef, - staticColumnIndex, - staticRowIndex, - table, -}) => { - const { - getState, - options: { - enableFilterMatchHighlighting, - mrtTheme: { matchHighlightColor }, - }, - } = table; - const { column, row } = cell; - const { columnDef } = column; - const { globalFilter, globalFilterFn } = getState(); - const filterValue = column.getFilterValue(); +const DataTable_TableBodyCellValue = ({ cell, rowRef, staticColumnIndex, staticRowIndex, table }) => { + const { + getState, + options: { + enableFilterMatchHighlighting, + mrtTheme: { matchHighlightColor }, + }, + } = table; + const { column, row } = cell; + const { columnDef } = column; + const { globalFilter, globalFilterFn } = getState(); + const filterValue = column.getFilterValue(); - let renderedCellValue = - cell.getIsAggregated() && columnDef.AggregatedCell - ? columnDef.AggregatedCell({ - cell, - column, - row, - table, - }) - : row.getIsGrouped() && !cell.getIsGrouped() - ? null - : cell.getIsGrouped() && columnDef.GroupedCell - ? columnDef.GroupedCell({ + let renderedCellValue = + cell.getIsAggregated() && columnDef.AggregatedCell + ? columnDef.AggregatedCell({ + cell, + column, + row, + table, + }) + : row.getIsGrouped() && !cell.getIsGrouped() + ? null + : cell.getIsGrouped() && columnDef.GroupedCell + ? columnDef.GroupedCell({ + cell, + column, + row, + table, + }) + : undefined; + + const isGroupedValue = renderedCellValue !== undefined; + + if (!isGroupedValue) { + renderedCellValue = cell.renderValue(); + } + + if ( + enableFilterMatchHighlighting && + columnDef.enableFilterMatchHighlighting !== false && + String(renderedCellValue) && + allowedTypes.includes(typeof renderedCellValue) && + ((filterValue && + allowedTypes.includes(typeof filterValue) && + ["autocomplete", "text"].includes(columnDef.filterVariant)) || + (globalFilter && allowedTypes.includes(typeof globalFilter) && column.getCanGlobalFilter())) + ) { + const chunks = highlightWords?.({ + matchExactly: (filterValue ? columnDef._filterFn : globalFilterFn) !== "fuzzy", + query: (filterValue ?? globalFilter ?? "").toString(), + text: renderedCellValue?.toString(), + }); + if (chunks?.length > 1 || chunks?.[0]?.match) { + renderedCellValue = ( + + {chunks?.map(({ key, match, text }) => ( + + )) ?? renderedCellValue} + + ); + } + } + + if (columnDef.Cell && !isGroupedValue) { + renderedCellValue = columnDef.Cell({ cell, column, + renderedCellValue, row, + rowRef, + staticColumnIndex, + staticRowIndex, table, - }) - : undefined; - - const isGroupedValue = renderedCellValue !== undefined; - - if (!isGroupedValue) { - renderedCellValue = cell.renderValue(); - } - - if ( - enableFilterMatchHighlighting && - columnDef.enableFilterMatchHighlighting !== false && - String(renderedCellValue) && - allowedTypes.includes(typeof renderedCellValue) && - ((filterValue && - allowedTypes.includes(typeof filterValue) && - ["autocomplete", "text"].includes(columnDef.filterVariant)) || - (globalFilter && - allowedTypes.includes(typeof globalFilter) && - column.getCanGlobalFilter())) - ) { - const chunks = highlightWords?.({ - matchExactly: - (filterValue ? columnDef._filterFn : globalFilterFn) !== "fuzzy", - query: (filterValue ?? globalFilter ?? "").toString(), - text: renderedCellValue?.toString(), - }); - if (chunks?.length > 1 || chunks?.[0]?.match) { - renderedCellValue = ( - - {chunks?.map(({ key, match, text }) => ( - - )) ?? renderedCellValue} - - ); + }); } - } - if (columnDef.Cell && !isGroupedValue) { - renderedCellValue = columnDef.Cell({ - cell, - column, - renderedCellValue, - row, - rowRef, - staticColumnIndex, - staticRowIndex, - table, - }); - } - - return renderedCellValue; + return renderedCellValue; }; export default DataTable_TableBodyCellValue; diff --git a/src/core/components/DataTable/body/TableBodyRow.js b/src/core/components/DataTable/body/TableBodyRow.js index e500eb0..a041d66 100644 --- a/src/core/components/DataTable/body/TableBodyRow.js +++ b/src/core/components/DataTable/body/TableBodyRow.js @@ -28,11 +28,7 @@ const DataTable_TableBodyRow = ({ enableStickyHeader, layoutMode, memoMode, - mrtTheme: { - baseBackgroundColor, - pinnedRowBackgroundColor, - selectedRowBackgroundColor, - }, + mrtTheme: { baseBackgroundColor, pinnedRowBackgroundColor, selectedRowBackgroundColor }, muiTableBodyRowProps, renderDetailPanel, rowPinningDisplayMode, @@ -40,21 +36,12 @@ const DataTable_TableBodyRow = ({ refs: { tableFooterRef, tableHeadRef }, setHoveredRow, } = table; - const { - density, - draggingColumn, - draggingRow, - editingCell, - editingRow, - hoveredRow, - isFullScreen, - rowPinning, - } = getState(); + const { density, draggingColumn, draggingRow, editingCell, editingRow, hoveredRow, isFullScreen, rowPinning } = + getState(); const visibleCells = row.getVisibleCells(); - const { virtualColumns, virtualPaddingLeft, virtualPaddingRight } = - columnVirtualizer ?? {}; + const { virtualColumns, virtualPaddingLeft, virtualPaddingRight } = columnVirtualizer ?? {}; const isRowSelected = getIsRowSelected({ row, table }); const isRowPinned = enableRowPinning && row.getIsPinned(); @@ -71,30 +58,17 @@ const DataTable_TableBodyRow = ({ }; const [bottomPinnedIndex, topPinnedIndex] = useMemo(() => { - if ( - !enableRowPinning || - !rowPinningDisplayMode?.includes('sticky') || - !pinnedRowIds || - !row.getIsPinned() - ) + if (!enableRowPinning || !rowPinningDisplayMode?.includes("sticky") || !pinnedRowIds || !row.getIsPinned()) return []; - return [ - [...pinnedRowIds].reverse().indexOf(row.id), - pinnedRowIds.indexOf(row.id), - ]; + return [[...pinnedRowIds].reverse().indexOf(row.id), pinnedRowIds.indexOf(row.id)]; }, [pinnedRowIds, rowPinning]); - const tableHeadHeight = - ((enableStickyHeader || isFullScreen) && - tableHeadRef.current?.clientHeight) || - 0; - const tableFooterHeight = - (enableStickyFooter && tableFooterRef.current?.clientHeight) || 0; + const tableHeadHeight = ((enableStickyHeader || isFullScreen) && tableHeadRef.current?.clientHeight) || 0; + const tableFooterHeight = (enableStickyFooter && tableFooterRef.current?.clientHeight) || 0; const sx = parseFromValuesOrFunc(tableRowProps?.sx, theme); - const defaultRowHeight = - density === 'compact' ? 37 : density === 'comfortable' ? 53 : 69; + const defaultRowHeight = density === "compact" ? 37 : density === "comfortable" ? 53 : 69; const customRowHeight = // @ts-ignore @@ -117,16 +91,16 @@ const DataTable_TableBodyRow = ({ const cellHighlightColor = isRowSelected ? selectedRowBackgroundColor : isRowPinned - ? pinnedRowBackgroundColor - : undefined; + ? pinnedRowBackgroundColor + : undefined; const cellHighlightColorHover = tableRowProps?.hover !== false ? isRowSelected ? cellHighlightColor - : theme.palette.mode === 'dark' - ? `${lighten(baseBackgroundColor, 0.3)}` - : `${darken(baseBackgroundColor, 0.3)}` + : theme.palette.mode === "dark" + ? `${lighten(baseBackgroundColor, 0.3)}` + : `${darken(baseBackgroundColor, 0.3)}` : undefined; return ( @@ -146,91 +120,81 @@ const DataTable_TableBodyRow = ({ selected={isRowSelected} {...tableRowProps} style={{ - transform: virtualRow - ? `translateY(${virtualRow.start}px)` - : undefined, + transform: virtualRow ? `translateY(${virtualRow.start}px)` : undefined, ...tableRowProps?.style, }} sx={(theme) => ({ - '&:hover td:after': cellHighlightColorHover + "&:hover td:after": cellHighlightColorHover ? { - backgroundColor: alpha(cellHighlightColorHover, 0.3), - ...commonCellBeforeAfterStyles, - } + backgroundColor: alpha(cellHighlightColorHover, 0.3), + ...commonCellBeforeAfterStyles, + } : undefined, backgroundColor: `${baseBackgroundColor} !important`, bottom: !virtualRow && bottomPinnedIndex !== undefined && isRowPinned - ? `${bottomPinnedIndex * rowHeight + - (enableStickyFooter ? tableFooterHeight - 1 : 0) - }px` + ? `${bottomPinnedIndex * rowHeight + (enableStickyFooter ? tableFooterHeight - 1 : 0)}px` : undefined, - boxSizing: 'border-box', - display: layoutMode?.startsWith('grid') ? 'flex' : undefined, + boxSizing: "border-box", + display: layoutMode?.startsWith("grid") ? "flex" : undefined, opacity: isRowPinned ? 0.97 : isDraggingRow || isHoveredRow ? 0.5 : 1, position: virtualRow - ? 'absolute' - : rowPinningDisplayMode?.includes('sticky') && isRowPinned - ? 'sticky' - : 'relative', + ? "absolute" + : rowPinningDisplayMode?.includes("sticky") && isRowPinned + ? "sticky" + : "relative", td: { ...getCommonPinnedCellStyles({ table, theme }), }, - 'td:after': cellHighlightColor + "td:after": cellHighlightColor ? { - backgroundColor: cellHighlightColor, - ...commonCellBeforeAfterStyles, - } + backgroundColor: cellHighlightColor, + ...commonCellBeforeAfterStyles, + } : undefined, top: virtualRow ? 0 : topPinnedIndex !== undefined && isRowPinned - ? `${topPinnedIndex * rowHeight + - (enableStickyHeader || isFullScreen ? tableHeadHeight - 1 : 0) + ? `${ + topPinnedIndex * rowHeight + + (enableStickyHeader || isFullScreen ? tableHeadHeight - 1 : 0) }px` - : undefined, - transition: virtualRow ? 'none' : 'all 150ms ease-in-out', - width: '100%', - zIndex: - rowPinningDisplayMode?.includes('sticky') && isRowPinned ? 2 : 0, - ...(sx), + : undefined, + transition: virtualRow ? "none" : "all 150ms ease-in-out", + width: "100%", + zIndex: rowPinningDisplayMode?.includes("sticky") && isRowPinned ? 2 : 0, + ...sx, })} > - {virtualPaddingLeft ? ( - - ) : null} - {(virtualColumns ?? visibleCells).map( - (cellOrVirtualCell, staticColumnIndex) => { - let cell = cellOrVirtualCell; - if (columnVirtualizer) { - staticColumnIndex = (cellOrVirtualCell).index; - cell = visibleCells[staticColumnIndex]; - } - const props = { - cell, - numRows, - rowRef, - staticColumnIndex, - staticRowIndex, - table, - }; - return cell ? ( - memoMode === 'cells' && - cell.column.columnDef.columnDefType === 'data' && - !draggingColumn && - !draggingRow && - editingCell?.id !== cell.id && - editingRow?.id !== row.id ? ( - - ) : ( - - ) - ) : null; - }, - )} - {virtualPaddingRight ? ( - - ) : null} + {virtualPaddingLeft ? : null} + {(virtualColumns ?? visibleCells).map((cellOrVirtualCell, staticColumnIndex) => { + let cell = cellOrVirtualCell; + if (columnVirtualizer) { + staticColumnIndex = cellOrVirtualCell.index; + cell = visibleCells[staticColumnIndex]; + } + const props = { + cell, + numRows, + rowRef, + staticColumnIndex, + staticRowIndex, + table, + }; + return cell ? ( + memoMode === "cells" && + cell.column.columnDef.columnDefType === "data" && + !draggingColumn && + !draggingRow && + editingCell?.id !== cell.id && + editingRow?.id !== row.id ? ( + + ) : ( + + ) + ) : null; + })} + {virtualPaddingRight ? : null} {renderDetailPanel && !row.getIsGrouped() && ( ); -} -export default DataTable_TableBodyRow +}; +export default DataTable_TableBodyRow; export const Memo_DataTable_TableBodyRow = memo( DataTable_TableBodyRow, - (prev, next) => - prev.row === next.row && prev.staticRowIndex === next.staticRowIndex, -); \ No newline at end of file + (prev, next) => prev.row === next.row && prev.staticRowIndex === next.staticRowIndex +); diff --git a/src/core/components/DataTable/body/TableDetailPanel.js b/src/core/components/DataTable/body/TableDetailPanel.js index 0c9f8a9..853aab5 100644 --- a/src/core/components/DataTable/body/TableDetailPanel.js +++ b/src/core/components/DataTable/body/TableDetailPanel.js @@ -23,7 +23,6 @@ const DataTable_TableDetailPanel = ({ } = table; const { isLoading } = getState(); - const tableRowProps = parseFromValuesOrFunc(muiTableBodyRowProps, { isDetailPanel: true, row, @@ -52,16 +51,12 @@ const DataTable_TableDetailPanel = ({ }} {...tableRowProps} sx={(theme) => ({ - display: layoutMode?.startsWith('grid') ? 'flex' : undefined, - position: virtualRow ? 'absolute' : undefined, - top: virtualRow - ? `${parentRowRef.current?.getBoundingClientRect()?.height}px` - : undefined, - transform: virtualRow - ? `translateY(${virtualRow?.start}px)` - : undefined, - width: '100%', - ...(parseFromValuesOrFunc(tableRowProps?.sx, theme)), + display: layoutMode?.startsWith("grid") ? "flex" : undefined, + position: virtualRow ? "absolute" : undefined, + top: virtualRow ? `${parentRowRef.current?.getBoundingClientRect()?.height}px` : undefined, + transform: virtualRow ? `translateY(${virtualRow?.start}px)` : undefined, + width: "100%", + ...parseFromValuesOrFunc(tableRowProps?.sx, theme), })} > ({ backgroundColor: virtualRow ? baseBackgroundColor : undefined, - borderBottom: !row.getIsExpanded() ? 'none' : undefined, - display: layoutMode?.startsWith('grid') ? 'flex' : undefined, - py: !!DetailPanel && row.getIsExpanded() ? '1rem' : 0, - transition: !virtualRow ? 'all 150ms ease-in-out' : undefined, + borderBottom: !row.getIsExpanded() ? "none" : undefined, + display: layoutMode?.startsWith("grid") ? "flex" : undefined, + py: !!DetailPanel && row.getIsExpanded() ? "1rem" : 0, + transition: !virtualRow ? "all 150ms ease-in-out" : undefined, width: `100%`, - ...(parseFromValuesOrFunc(tableCellProps?.sx, theme)), + ...parseFromValuesOrFunc(tableCellProps?.sx, theme), })} > {virtualRow ? ( @@ -88,6 +83,5 @@ const DataTable_TableDetailPanel = ({ ); - -} -export default DataTable_TableDetailPanel \ No newline at end of file +}; +export default DataTable_TableDetailPanel; diff --git a/src/core/components/DataTable/buttons/CopyButton.js b/src/core/components/DataTable/buttons/CopyButton.js index c8878e0..c4dfe4b 100644 --- a/src/core/components/DataTable/buttons/CopyButton.js +++ b/src/core/components/DataTable/buttons/CopyButton.js @@ -2,11 +2,7 @@ import { getCommonTooltipProps, parseFromValuesOrFunc } from "@/core/utils/utils import { Button, Tooltip } from "@mui/material"; import { useState } from "react"; -const DataTable_CopyButton = ({ - cell, - table, - ...rest -}) => { +const DataTable_CopyButton = ({ cell, table, ...rest }) => { const { options: { localization, muiCopyButtonProps }, } = table; @@ -40,11 +36,8 @@ const DataTable_CopyButton = ({ return ( - - - )} + + {({ + values, + handleChange, + handleBlur, + setFieldValue, + errors, + touched, + isSubmitting, + isValid, + dirty, + resetForm, + }) => ( +
+ + {columns.map( + (column) => + column.enableColumnFilter && ( + + ) + )} + + + + +
+ )}
)} @@ -204,4 +221,4 @@ function FilterBody({columns, drawerState, setDrawerState, user_id, page_name, t ); } -export default FilterBody; \ No newline at end of file +export default FilterBody; diff --git a/src/core/components/DataTable/filter/FilterBodyField.jsx b/src/core/components/DataTable/filter/FilterBodyField.jsx index b12e770..a9bef12 100644 --- a/src/core/components/DataTable/filter/FilterBodyField.jsx +++ b/src/core/components/DataTable/filter/FilterBodyField.jsx @@ -1,4 +1,4 @@ -import {useState} from "react"; +import { useState } from "react"; import FilterOptionList from "@/core/components/DataTable/filter/FilterOptionList"; import CustomSelect from "@/core/components/DataTable/filter/fieldsType/CustomSelect"; import CustomTextField from "@/core/components/DataTable/filter/fieldsType/CustomTextField"; @@ -14,19 +14,19 @@ const columnFilterModeOptionFa = { lessThan: "کوچکتر", greaterThan: "بزرگتر", fuzzy: "فازی", - between: "مابین" + between: "مابین", }; function FilterBodyField({ - column, - filterParameters, - handleChange, - handleBlur, - setFieldValue, - errors, - touched, - resetForm - }) { + column, + filterParameters, + handleChange, + handleBlur, + setFieldValue, + errors, + touched, + resetForm, +}) { const [anchorEl, setAnchorEl] = useState(null); const defaultFilterTranslation = columnFilterModeOptionFa[filterParameters.filterFn] || filterParameters.filterFn; @@ -47,7 +47,9 @@ function FilterBodyField({ errors={errors} touched={touched} /> - ) : filterParameters.datatype === "numeric" && filterParameters.filterFn === "equals" && Array.isArray(column.columnSelectOption) ? ( + ) : filterParameters.datatype === "numeric" && + filterParameters.filterFn === "equals" && + Array.isArray(column.columnSelectOption) ? ( - { - setDrawerState(!drawerState) - }} aria-label="filter table"> - + { + setDrawerState(!drawerState); + }} + aria-label="filter table" + > +
); diff --git a/src/core/components/DataTable/filter/FilterHeader.jsx b/src/core/components/DataTable/filter/FilterHeader.jsx index 2acd0b7..76980ce 100644 --- a/src/core/components/DataTable/filter/FilterHeader.jsx +++ b/src/core/components/DataTable/filter/FilterHeader.jsx @@ -1,10 +1,10 @@ -'use client' +"use client"; -import {Box, IconButton, Typography} from "@mui/material"; -import CancelIcon from '@mui/icons-material/Cancel'; -import FilterAltIcon from '@mui/icons-material/FilterAlt'; +import { Box, IconButton, Typography } from "@mui/material"; +import CancelIcon from "@mui/icons-material/Cancel"; +import FilterAltIcon from "@mui/icons-material/FilterAlt"; -function FilterHeader({setDrawerState}) { +function FilterHeader({ setDrawerState }) { return ( - - - فیلتر + + + + فیلتر + - setDrawerState(false)}> - + setDrawerState(false)}> + ); } -export default FilterHeader; \ No newline at end of file +export default FilterHeader; diff --git a/src/core/components/DataTable/filter/FilterOptionList.jsx b/src/core/components/DataTable/filter/FilterOptionList.jsx index ce02c23..e088832 100644 --- a/src/core/components/DataTable/filter/FilterOptionList.jsx +++ b/src/core/components/DataTable/filter/FilterOptionList.jsx @@ -1,17 +1,17 @@ -'use client' +"use client"; -import {ListItem, Menu} from "@mui/material"; -import {useState} from "react"; +import { ListItem, Menu } from "@mui/material"; +import { useState } from "react"; function FilterOptionList({ - column, - filterType, - filterOption, - anchorEl, - columnFilterModeOptionFa, - setAnchorEl, - setFieldValue - }) { + column, + filterType, + filterOption, + anchorEl, + columnFilterModeOptionFa, + setAnchorEl, + setFieldValue, +}) { const [selectedFilter, setSelectedFilter] = useState(filterType); const handleChangeItem = (event, index) => { @@ -19,25 +19,26 @@ function FilterOptionList({ setFieldValue(`${column.id}.filterFn`, filterOption[index]); setSelectedFilter(filterOption[index]); setAnchorEl(null); - } + }; const handleCloseFilterBox = () => { setAnchorEl(null); }; return ( - + {filterOption.map((option, index) => ( - handleChangeItem(event, index)} - selected={option === selectedFilter} - sx={{cursor: 'pointer', width: "100px", display: "flex", justifyContent: "center"}}> + handleChangeItem(event, index)} + selected={option === selectedFilter} + sx={{ + cursor: "pointer", + width: "100px", + display: "flex", + justifyContent: "center", + }} + > {columnFilterModeOptionFa[option]} ))} @@ -45,4 +46,4 @@ function FilterOptionList({ ); } -export default FilterOptionList; \ No newline at end of file +export default FilterOptionList; diff --git a/src/core/components/DataTable/filter/fieldsType/CustomDate/CustomDatePicker.jsx b/src/core/components/DataTable/filter/fieldsType/CustomDate/CustomDatePicker.jsx index e92a426..fe5d2e0 100644 --- a/src/core/components/DataTable/filter/fieldsType/CustomDate/CustomDatePicker.jsx +++ b/src/core/components/DataTable/filter/fieldsType/CustomDate/CustomDatePicker.jsx @@ -1,8 +1,8 @@ -import React from 'react'; +import React from "react"; import MuiDatePicker from "@/core/components/DataTable/filter/fieldsType/CustomDate/MuiDatePicker"; -import {Typography} from "@mui/material"; +import { Typography } from "@mui/material"; -function CustomDatePicker({column, filterParameters, defaultFilterTranslation, setFieldValue}) { +function CustomDatePicker({ column, filterParameters, defaultFilterTranslation, setFieldValue }) { return ( + نوع فیلتر: {defaultFilterTranslation} (تاریخ) } @@ -18,4 +18,4 @@ function CustomDatePicker({column, filterParameters, defaultFilterTranslation, s ); } -export default CustomDatePicker; \ No newline at end of file +export default CustomDatePicker; diff --git a/src/core/components/DataTable/filter/fieldsType/CustomDate/CustomDatePickerRange.jsx b/src/core/components/DataTable/filter/fieldsType/CustomDate/CustomDatePickerRange.jsx index b870061..116af77 100644 --- a/src/core/components/DataTable/filter/fieldsType/CustomDate/CustomDatePickerRange.jsx +++ b/src/core/components/DataTable/filter/fieldsType/CustomDate/CustomDatePickerRange.jsx @@ -1,12 +1,12 @@ -'use client' +"use client"; import React from "react"; -import {Box, Typography} from "@mui/material"; +import { Box, Typography } from "@mui/material"; import MuiDatePicker from "@/core/components/DataTable/filter/fieldsType/CustomDate/MuiDatePicker"; -function CustomDatePickerRange({column, filterParameters, defaultFilterTranslation, setFieldValue, errors, touched}) { +function CustomDatePickerRange({ column, filterParameters, defaultFilterTranslation, setFieldValue, errors, touched }) { return ( - + + نوع فیلتر: {defaultFilterTranslation} (تاریخ) } diff --git a/src/core/components/DataTable/filter/fieldsType/CustomDate/MuiDatePicker.jsx b/src/core/components/DataTable/filter/fieldsType/CustomDate/MuiDatePicker.jsx index 5031372..d715192 100644 --- a/src/core/components/DataTable/filter/fieldsType/CustomDate/MuiDatePicker.jsx +++ b/src/core/components/DataTable/filter/fieldsType/CustomDate/MuiDatePicker.jsx @@ -1,33 +1,31 @@ -import React from 'react'; -import {LocalizationProvider, MobileDatePicker} from "@mui/x-date-pickers"; -import {AdapterDateFnsJalali} from "@mui/x-date-pickers/AdapterDateFnsJalali"; -import {faIR} from "@mui/x-date-pickers/locales"; -import {Box, FormHelperText, IconButton, InputAdornment} from "@mui/material"; +import React from "react"; +import { LocalizationProvider, MobileDatePicker } from "@mui/x-date-pickers"; +import { AdapterDateFnsJalali } from "@mui/x-date-pickers/AdapterDateFnsJalali"; +import { faIR } from "@mui/x-date-pickers/locales"; +import { Box, FormHelperText, IconButton, InputAdornment } from "@mui/material"; import ClearIcon from "@mui/icons-material/Clear"; import moment from "jalali-moment"; -function MuiDatePicker({value, setFieldValue, name, minDate, maxDate, helperText, placeholder, error}) { - +function MuiDatePicker({ value, setFieldValue, name, minDate, maxDate, helperText, placeholder, error }) { // console.log("error", error); // // console.log("helperText", helperText) return ( - - + { const date = new Date(value); - const formattedDate = moment(date) - .locale("en") - .format("YYYY-MM-DD"); + const formattedDate = moment(date).locale("en").format("YYYY-MM-DD"); setFieldValue(name, formattedDate); }} minDate={minDate ? new Date(minDate) : null} @@ -47,13 +45,13 @@ function MuiDatePicker({value, setFieldValue, name, minDate, maxDate, helperText }} sx={{ color: "#bfbfbf", - '&:hover': { - backgroundColor: 'rgba(189, 189, 189, 0.1)', - color: "#363434" + "&:hover": { + backgroundColor: "rgba(189, 189, 189, 0.1)", + color: "#363434", }, }} > - + ), @@ -61,7 +59,7 @@ function MuiDatePicker({value, setFieldValue, name, minDate, maxDate, helperText }, }} /> - + {helperText ? helperText : ""} @@ -69,4 +67,4 @@ function MuiDatePicker({value, setFieldValue, name, minDate, maxDate, helperText ); } -export default MuiDatePicker; \ No newline at end of file +export default MuiDatePicker; diff --git a/src/core/components/DataTable/filter/fieldsType/CustomSelect.jsx b/src/core/components/DataTable/filter/fieldsType/CustomSelect.jsx index 44f0599..bd038e2 100644 --- a/src/core/components/DataTable/filter/fieldsType/CustomSelect.jsx +++ b/src/core/components/DataTable/filter/fieldsType/CustomSelect.jsx @@ -1,35 +1,32 @@ -'use client' +"use client"; -import {FormControl, FormHelperText, InputLabel, MenuItem, OutlinedInput, Select, Typography} from "@mui/material"; +import { FormControl, FormHelperText, InputLabel, MenuItem, OutlinedInput, Select, Typography } from "@mui/material"; -function CustomSelect({column, filterParameters, defaultFilterTranslation, setFieldValue}) { +function CustomSelect({ column, filterParameters, defaultFilterTranslation, setFieldValue }) { const columnSelectOption = column.columnSelectOption; return ( - + {column.header} - + نوع فیلتر: {defaultFilterTranslation} diff --git a/src/core/components/DataTable/filter/fieldsType/CustomSelectMultiple.jsx b/src/core/components/DataTable/filter/fieldsType/CustomSelectMultiple.jsx index ae027fe..130f98f 100644 --- a/src/core/components/DataTable/filter/fieldsType/CustomSelectMultiple.jsx +++ b/src/core/components/DataTable/filter/fieldsType/CustomSelectMultiple.jsx @@ -1,4 +1,4 @@ -'use client' +"use client"; import { Box, @@ -9,49 +9,47 @@ import { MenuItem, OutlinedInput, Select, - Typography + Typography, } from "@mui/material"; -function CustomSelectMultiple({column, filterParameters, defaultFilterTranslation, setFieldValue}) { +function CustomSelectMultiple({ column, filterParameters, defaultFilterTranslation, setFieldValue }) { const columnSelectOption = column.columnSelectOption; const getLabelForValue = (value) => { - const option = columnSelectOption.find(opt => opt.value === value); + const option = columnSelectOption.find((opt) => opt.value === value); return option ? option.label : value; }; return ( - - {column.header} + + + {column.header} + - + نوع فیلتر: {defaultFilterTranslation} diff --git a/src/core/components/DataTable/filter/fieldsType/CustomTextField.jsx b/src/core/components/DataTable/filter/fieldsType/CustomTextField.jsx index eacd820..05b44ce 100644 --- a/src/core/components/DataTable/filter/fieldsType/CustomTextField.jsx +++ b/src/core/components/DataTable/filter/fieldsType/CustomTextField.jsx @@ -1,15 +1,14 @@ -import {InputAdornment, TextField, Typography} from "@mui/material"; -import FilterListIcon from '@mui/icons-material/FilterList'; +import { InputAdornment, TextField, Typography } from "@mui/material"; +import FilterListIcon from "@mui/icons-material/FilterList"; function CustomTextField({ - column, - filterParameters, - defaultFilterTranslation, - handleOpenFilterBox, - handleChange, - handleBlur - }) { - + column, + filterParameters, + defaultFilterTranslation, + handleOpenFilterBox, + handleChange, + handleBlur, +}) { return ( - نوع فیلتر: {defaultFilterTranslation} - } + helperText={ + + نوع فیلتر: {defaultFilterTranslation} + + } variant="outlined" size="normal" - sx={{marginY: 1}} + sx={{ marginY: 1 }} InputProps={{ endAdornment: ( - - + + ), }} @@ -36,4 +37,4 @@ function CustomTextField({ ); } -export default CustomTextField; \ No newline at end of file +export default CustomTextField; diff --git a/src/core/components/DataTable/filter/fieldsType/CustomTextFieldRange.jsx b/src/core/components/DataTable/filter/fieldsType/CustomTextFieldRange.jsx index 35c9358..fea4169 100644 --- a/src/core/components/DataTable/filter/fieldsType/CustomTextFieldRange.jsx +++ b/src/core/components/DataTable/filter/fieldsType/CustomTextFieldRange.jsx @@ -1,18 +1,18 @@ -import {Box, InputAdornment, TextField, Typography} from "@mui/material"; -import FilterListIcon from '@mui/icons-material/FilterList'; +import { Box, InputAdornment, TextField, Typography } from "@mui/material"; +import FilterListIcon from "@mui/icons-material/FilterList"; function CustomTextFieldRange({ - column, - filterParameters, - defaultFilterTranslation, - handleOpenFilterBox, - handleChange, - handleBlur, - errors, - touched - }) { + column, + filterParameters, + defaultFilterTranslation, + handleOpenFilterBox, + handleChange, + handleBlur, + errors, + touched, +}) { return ( - + نوع - فیلتر: {defaultFilterTranslation}} + helperText={ + + نوع فیلتر: {defaultFilterTranslation} + + } variant="outlined" size="normal" - sx={{marginY: 1, marginRight: 1}} + sx={{ marginY: 1, marginRight: 1 }} /> - + + ), }} @@ -53,4 +56,4 @@ function CustomTextFieldRange({ ); } -export default CustomTextFieldRange; \ No newline at end of file +export default CustomTextFieldRange; diff --git a/src/core/components/DataTable/filter/index.jsx b/src/core/components/DataTable/filter/index.jsx index 65a93d2..8d26594 100644 --- a/src/core/components/DataTable/filter/index.jsx +++ b/src/core/components/DataTable/filter/index.jsx @@ -1,17 +1,23 @@ -'use client' +"use client"; -import {useState} from "react"; +import { useState } from "react"; import FilterButton from "@/core/components/DataTable/filter/FilterButton"; import FilterBody from "@/core/components/DataTable/filter/FilterBody"; -function FilterColumn({columns, user_id, page_name, table_name}) { +function FilterColumn({ columns, user_id, page_name, table_name }) { const [open, setOpen] = useState(false); return ( <> - - + + ); } diff --git a/src/core/components/DataTable/head/TableHead.js b/src/core/components/DataTable/head/TableHead.js index 5e5dd99..39ee214 100644 --- a/src/core/components/DataTable/head/TableHead.js +++ b/src/core/components/DataTable/head/TableHead.js @@ -1,26 +1,17 @@ -import {parseFromValuesOrFunc} from "@/core/utils/utils"; -import {TableHead} from "@mui/material"; +import { parseFromValuesOrFunc } from "@/core/utils/utils"; +import { TableHead } from "@mui/material"; import DataTable_TableHeadRow from "./TableHeadRow"; -const DataTable_TableHead = ({ - columnVirtualizer, - table, - ...rest - }) => { +const DataTable_TableHead = ({ columnVirtualizer, table, ...rest }) => { const { getState, - options: { - enableStickyHeader, - layoutMode, - muiTableHeadProps, - positionToolbarAlertBanner, - }, - refs: {tableHeadRef}, + options: { enableStickyHeader, layoutMode, muiTableHeadProps, positionToolbarAlertBanner }, + refs: { tableHeadRef }, } = table; - const {isFullScreen, showAlertBanner} = getState(); + const { isFullScreen, showAlertBanner } = getState(); const tableHeadProps = { - ...parseFromValuesOrFunc(muiTableHeadProps, {table}), + ...parseFromValuesOrFunc(muiTableHeadProps, { table }), ...rest, }; @@ -37,28 +28,24 @@ const DataTable_TableHead = ({ } }} sx={(theme) => ({ - display: layoutMode?.startsWith('grid') ? 'grid' : undefined, + display: layoutMode?.startsWith("grid") ? "grid" : undefined, opacity: 0.97, - position: stickyHeader ? 'sticky' : 'relative', - top: stickyHeader && layoutMode?.startsWith('grid') ? 0 : undefined, + position: stickyHeader ? "sticky" : "relative", + top: stickyHeader && layoutMode?.startsWith("grid") ? 0 : undefined, zIndex: stickyHeader ? 2 : undefined, - ...(parseFromValuesOrFunc(tableHeadProps?.sx, theme)), + ...parseFromValuesOrFunc(tableHeadProps?.sx, theme), })} > - {table - .getHeaderGroups() - .map((headerGroup, index) => ( - - )) - } + {table.getHeaderGroups().map((headerGroup, index) => ( + + ))} ); - -} -export default DataTable_TableHead \ No newline at end of file +}; +export default DataTable_TableHead; diff --git a/src/core/components/DataTable/head/TableHeadCell.js b/src/core/components/DataTable/head/TableHeadCell.js index 6248d63..a0b8fc5 100644 --- a/src/core/components/DataTable/head/TableHeadCell.js +++ b/src/core/components/DataTable/head/TableHeadCell.js @@ -1,16 +1,10 @@ -import {getCommonMRTCellStyles, parseFromValuesOrFunc} from "@/core/utils/utils"; -import {useTheme} from "@emotion/react"; -import {Box, TableCell} from "@mui/material"; -import {MRT_TableHeadCellSortLabel} from "material-react-table"; -import {useMemo} from "react"; +import { getCommonMRTCellStyles, parseFromValuesOrFunc } from "@/core/utils/utils"; +import { useTheme } from "@emotion/react"; +import { Box, TableCell } from "@mui/material"; +import { MRT_TableHeadCellSortLabel } from "material-react-table"; +import { useMemo } from "react"; -const DataTable_TableHeadCell = ({ - columnVirtualizer, - header, - staticColumnIndex, - table, - ...rest - }) => { +const DataTable_TableHeadCell = ({ columnVirtualizer, header, staticColumnIndex, table, ...rest }) => { const theme = useTheme(); const { getState, @@ -24,26 +18,19 @@ const DataTable_TableHeadCell = ({ enableGrouping, enableMultiSort, layoutMode, - mrtTheme: {draggingBorderColor}, + mrtTheme: { draggingBorderColor }, muiTableHeadCellProps, }, - refs: {tableHeadCellRefs}, + refs: { tableHeadCellRefs }, setHoveredColumn, } = table; - const { - columnSizingInfo, - density, - draggingColumn, - grouping, - hoveredColumn, - showColumnFilters, - } = getState(); - const {column} = header; - const {columnDef} = column; - const {columnDefType} = columnDef; + const { columnSizingInfo, density, draggingColumn, grouping, hoveredColumn, showColumnFilters } = getState(); + const { column } = header; + const { columnDef } = column; + const { columnDefType } = columnDef; const tableCellProps = { - ...parseFromValuesOrFunc(muiTableHeadCellProps, {column, table}), + ...parseFromValuesOrFunc(muiTableHeadCellProps, { column, table }), ...parseFromValuesOrFunc(columnDef.muiTableHeadCellProps, { column, table, @@ -51,23 +38,17 @@ const DataTable_TableHeadCell = ({ ...rest, }; - const isColumnPinned = - enableColumnPinning && - columnDef.columnDefType !== 'group' && - column.getIsPinned(); + const isColumnPinned = enableColumnPinning && columnDef.columnDefType !== "group" && column.getIsPinned(); const showColumnActions = - (enableColumnActions || columnDef.enableColumnActions) && - columnDef.enableColumnActions !== false; + (enableColumnActions || columnDef.enableColumnActions) && columnDef.enableColumnActions !== false; const showDragHandle = enableColumnDragging !== false && columnDef.enableColumnDragging !== false && (enableColumnDragging || (enableColumnOrdering && columnDef.enableColumnOrdering !== false) || - (enableGrouping && - columnDef.enableGrouping !== false && - !grouping.includes(column.id))); + (enableGrouping && columnDef.enableGrouping !== false && !grouping.includes(column.id))); const headerPL = useMemo(() => { let pl = 0; @@ -80,41 +61,37 @@ const DataTable_TableHeadCell = ({ const draggingBorders = useMemo(() => { const showResizeBorder = columnSizingInfo.isResizingColumn === column.id && - columnResizeMode === 'onChange' && + columnResizeMode === "onChange" && !header.subHeaders.length; const borderStyle = showResizeBorder ? `2px solid ${draggingBorderColor} !important` : draggingColumn?.id === column.id - ? `1px dashed ${theme.palette.grey[500]}` - : hoveredColumn?.id === column.id - ? `2px dashed ${draggingBorderColor}` - : undefined; + ? `1px dashed ${theme.palette.grey[500]}` + : hoveredColumn?.id === column.id + ? `2px dashed ${draggingBorderColor}` + : undefined; if (showResizeBorder) { - return columnResizeDirection === 'ltr' - ? {borderRight: borderStyle} - : {borderLeft: borderStyle}; + return columnResizeDirection === "ltr" ? { borderRight: borderStyle } : { borderLeft: borderStyle }; } const draggingBorders = borderStyle ? { - borderLeft: borderStyle, - borderRight: borderStyle, - borderTop: borderStyle, - } + borderLeft: borderStyle, + borderRight: borderStyle, + borderTop: borderStyle, + } : undefined; return draggingBorders; }, [draggingColumn, hoveredColumn, columnSizingInfo.isResizingColumn]); const handleDragEnter = (_e) => { - if (enableGrouping && hoveredColumn?.id === 'drop-zone') { + if (enableGrouping && hoveredColumn?.id === "drop-zone") { setHoveredColumn(null); } - if (enableColumnOrdering && draggingColumn && columnDefType !== 'group') { - setHoveredColumn( - columnDef.enableColumnOrdering !== false ? column : null, - ); + if (enableColumnOrdering && draggingColumn && columnDefType !== "group") { + setHoveredColumn(columnDef.enableColumnOrdering !== false ? column : null); } }; @@ -124,7 +101,6 @@ const DataTable_TableHeadCell = ({ } }; - const HeaderElement = parseFromValuesOrFunc(columnDef.Header, { column, @@ -132,12 +108,9 @@ const DataTable_TableHeadCell = ({ table, }) ?? columnDef.header; - const columnRelativeDepth = header.depth - column.depth; - if ( - columnRelativeDepth > 1 - ) { + if (columnRelativeDepth > 1) { return null; } @@ -149,13 +122,7 @@ const DataTable_TableHeadCell = ({ return ( { if (node) { tableHeadCellRefs.current[column.id] = node; - if (columnDefType !== 'group') { + if (columnDefType !== "group") { columnVirtualizer?.measureElement?.(node); } } }} {...tableCellProps} sx={(theme) => ({ - '& :hover': { - '.MuiButtonBase-root': { - opacity: 1, - }, + "& :hover": { + ".MuiButtonBase-root": { + opacity: 1, }, - flexDirection: layoutMode?.startsWith('grid') ? 'column' : undefined, - fontWeight: 'bold', - overflow: 'visible', - p: - density === 'compact' - ? '0.5rem' - : density === 'comfortable' - ? columnDefType === 'display' - ? '0.75rem' - : '1rem' - : columnDefType === 'display' - ? '1rem 1.25rem' - : '1.5rem', - pb: - columnDefType === 'display' - ? 0 - : showColumnFilters || density === 'compact' - ? '0.4rem' - : '0.6rem', - pt: - columnDefType === 'group' || density === 'compact' - ? '0.25rem' - : density === 'comfortable' - ? '.75rem' - : '1.25rem', - userSelect: enableMultiSort && column.getCanSort() ? 'none' : undefined, - verticalAlign: 'middle', - ...getCommonMRTCellStyles({ - column, - header, - table, - tableCellProps, - theme, - }), - ...draggingBorders, - } - )} + }, + flexDirection: layoutMode?.startsWith("grid") ? "column" : undefined, + fontWeight: "bold", + overflow: "visible", + p: + density === "compact" + ? "0.5rem" + : density === "comfortable" + ? columnDefType === "display" + ? "0.75rem" + : "1rem" + : columnDefType === "display" + ? "1rem 1.25rem" + : "1.5rem", + pb: columnDefType === "display" ? 0 : showColumnFilters || density === "compact" ? "0.4rem" : "0.6rem", + pt: + columnDefType === "group" || density === "compact" + ? "0.25rem" + : density === "comfortable" + ? ".75rem" + : "1.25rem", + userSelect: enableMultiSort && column.getCanSort() ? "none" : undefined, + verticalAlign: "middle", + ...getCommonMRTCellStyles({ + column, + header, + table, + tableCellProps, + theme, + }), + ...draggingBorders, + })} > {tableCellProps.children ?? ( {HeaderElement} - {(column.getCanSort() && columnDefType !== 'group') && ( - + {column.getCanSort() && columnDefType !== "group" && ( + )} )} ); - -} -export default DataTable_TableHeadCell; \ No newline at end of file +}; +export default DataTable_TableHeadCell; diff --git a/src/core/components/DataTable/head/TableHeadRow.js b/src/core/components/DataTable/head/TableHeadRow.js index 33a23e2..512147a 100644 --- a/src/core/components/DataTable/head/TableHeadRow.js +++ b/src/core/components/DataTable/head/TableHeadRow.js @@ -1,25 +1,20 @@ -import {parseFromValuesOrFunc} from "@/core/utils/utils"; -import {TableRow} from "@mui/material"; +import { parseFromValuesOrFunc } from "@/core/utils/utils"; +import { TableRow } from "@mui/material"; import DataTable_TableHeadCell from "./TableHeadCell"; const DataTable_TableHeadRow = ({ - columnVirtualizer, - headerGroup, - table, - index, // Add index prop - ...rest - }) => { + columnVirtualizer, + headerGroup, + table, + index, // Add index prop + ...rest +}) => { const { - options: { - enableStickyHeader, - layoutMode, - muiTableHeadRowProps, - }, + options: { enableStickyHeader, layoutMode, muiTableHeadRowProps }, } = table; - const {virtualColumns, virtualPaddingLeft, virtualPaddingRight} = - columnVirtualizer ?? {}; + const { virtualColumns, virtualPaddingLeft, virtualPaddingRight } = columnVirtualizer ?? {}; - const backgroundColor = index % 2 === 0 ? '#015688' : '#ff5c0f'; + const backgroundColor = index % 2 === 0 ? "#015688" : "#ff5c0f"; const tableRowProps = { ...parseFromValuesOrFunc(muiTableHeadRowProps, { @@ -27,20 +22,23 @@ const DataTable_TableHeadRow = ({ table, }), ...rest, - sx: (theme) => ({ // Access theme from the sx function + sx: (theme) => ({ + // Access theme from the sx function ...(parseFromValuesOrFunc(muiTableHeadRowProps?.sx, theme) || {}), backgroundColor, // Apply background color - display: layoutMode?.startsWith('grid') ? 'flex' : undefined, - position: enableStickyHeader && layoutMode === 'semantic' ? 'sticky' : 'relative', + display: layoutMode?.startsWith("grid") ? "flex" : undefined, + position: enableStickyHeader && layoutMode === "semantic" ? "sticky" : "relative", top: 0, }), }; return ( - {virtualPaddingLeft && } + {virtualPaddingLeft && } {(virtualColumns ?? headerGroup.headers).map((headerOrVirtualHeader, staticColumnIndex) => { - const header = columnVirtualizer ? headerGroup.headers[headerOrVirtualHeader.index] : headerOrVirtualHeader; + const header = columnVirtualizer + ? headerGroup.headers[headerOrVirtualHeader.index] + : headerOrVirtualHeader; return header ? ( ) : null; })} - {virtualPaddingRight && } + {virtualPaddingRight && } ); }; -export default DataTable_TableHeadRow; \ No newline at end of file +export default DataTable_TableHeadRow; diff --git a/src/core/components/DataTable/index.js b/src/core/components/DataTable/index.js index e440895..f387d06 100644 --- a/src/core/components/DataTable/index.js +++ b/src/core/components/DataTable/index.js @@ -4,9 +4,9 @@ import DataTableProvider from "@/lib/contexts/DataTable"; const DataTable = (props) => { return ( - + ); }; -export default DataTable; \ No newline at end of file +export default DataTable; diff --git a/src/core/components/DataTable/localization/fa/datatable.js b/src/core/components/DataTable/localization/fa/datatable.js index f80b7e0..e36f366 100644 --- a/src/core/components/DataTable/localization/fa/datatable.js +++ b/src/core/components/DataTable/localization/fa/datatable.js @@ -67,8 +67,7 @@ export const FA_DATATABLE_LOCALIZATION = { rowsPerPage: "ردیف در هر صفحه", save: "ذخیره", search: "جستجو", - selectedCountOfRowCountRowsSelected: - "{selectedCount} از {rowCount} ردیف انتخاب شده", + selectedCountOfRowCountRowsSelected: "{selectedCount} از {rowCount} ردیف انتخاب شده", select: "انتخاب", showAll: "نمایش همه", showAllColumns: "نمایش همه ستون‌ها", @@ -89,4 +88,4 @@ export const FA_DATATABLE_LOCALIZATION = { unpin: "رها کردن", unpinAll: "رها کردن همه", unsorted: "بدون مرتب سازی", -}; \ No newline at end of file +}; diff --git a/src/core/components/DataTable/menus/ActionMenuItem.js b/src/core/components/DataTable/menus/ActionMenuItem.js index 2b208b9..012fcc5 100644 --- a/src/core/components/DataTable/menus/ActionMenuItem.js +++ b/src/core/components/DataTable/menus/ActionMenuItem.js @@ -1,12 +1,6 @@ import { Box, IconButton, ListItemIcon, MenuItem } from "@mui/material"; -const DataTable_ActionMenuItem = ({ - icon, - label, - onOpenSubMenu, - table, - ...rest -}) => { +const DataTable_ActionMenuItem = ({ icon, label, onOpenSubMenu, table, ...rest }) => { const { options: { icons: { ArrowRightIcon }, @@ -16,35 +10,29 @@ const DataTable_ActionMenuItem = ({ return ( {icon} {label} {onOpenSubMenu && ( - + )} ); - -} -export default DataTable_ActionMenuItem \ No newline at end of file +}; +export default DataTable_ActionMenuItem; diff --git a/src/core/components/DataTable/menus/CellActionMenu.js b/src/core/components/DataTable/menus/CellActionMenu.js index 36638e0..5b27ca9 100644 --- a/src/core/components/DataTable/menus/CellActionMenu.js +++ b/src/core/components/DataTable/menus/CellActionMenu.js @@ -2,10 +2,7 @@ import { parseFromValuesOrFunc } from "@/core/utils/utils"; import { Menu } from "@mui/material"; import DataTable_ActionMenuItem from "./ActionMenuItem"; -const DataTable_CellActionMenu = ({ - table, - ...rest -}) => { +const DataTable_CellActionMenu = ({ table, ...rest }) => { const { getState, options: { @@ -32,12 +29,11 @@ const DataTable_CellActionMenu = ({ }; const internalMenuItems = [ - (parseFromValuesOrFunc(enableClickToCopy, cell) === 'context-menu' || - parseFromValuesOrFunc(columnDef.enableClickToCopy, cell) === - 'context-menu') && ( + (parseFromValuesOrFunc(enableClickToCopy, cell) === "context-menu" || + parseFromValuesOrFunc(columnDef.enableClickToCopy, cell) === "context-menu") && ( } - key={'mrt-copy'} + key={"mrt-copy"} label={localization.copy} onClick={(event) => { event.stopPropagation(); @@ -47,10 +43,10 @@ const DataTable_CellActionMenu = ({ table={table} /> ), - parseFromValuesOrFunc(enableEditing, row) && editDisplayMode === 'cell' && ( + parseFromValuesOrFunc(enableEditing, row) && editDisplayMode === "cell" && ( } - key={'mrt-edit'} + key={"mrt-edit"} label={localization.edit} onClick={() => { openEditingCell({ cell, table }); @@ -71,14 +67,13 @@ const DataTable_CellActionMenu = ({ }; const menuItems = - columnDef.renderCellActionMenuItems?.(renderActionProps) ?? - renderCellActionMenuItems?.(renderActionProps); + columnDef.renderCellActionMenuItems?.(renderActionProps) ?? renderCellActionMenuItems?.(renderActionProps); return ( (!!menuItems?.length || !!internalMenuItems?.length) && ( ) ); - -} -export default DataTable_CellActionMenu \ No newline at end of file +}; +export default DataTable_CellActionMenu; diff --git a/src/core/components/DataTable/menus/ShowHideColumnsMenu.js b/src/core/components/DataTable/menus/ShowHideColumnsMenu.js index 12efae8..cb0423c 100644 --- a/src/core/components/DataTable/menus/ShowHideColumnsMenu.js +++ b/src/core/components/DataTable/menus/ShowHideColumnsMenu.js @@ -2,11 +2,7 @@ import { Box, Button, Divider, Menu } from "@mui/material"; import { useMemo, useState } from "react"; import DataTable_ShowHideColumnsMenuItems from "./ShowHideColumnsMenuItems"; -const DataTable_ShowHideColumnsMenu = ({ anchorEl, - setAnchorEl, - table, - ...rest -}) => { +const DataTable_ShowHideColumnsMenu = ({ anchorEl, setAnchorEl, table, ...rest }) => { const { getAllColumns, getAllLeafColumns, @@ -36,14 +32,11 @@ const DataTable_ShowHideColumnsMenu = ({ anchorEl, const allColumns = useMemo(() => { const columns = getAllColumns(); - if ( - columnOrder.length > 0 && - !columns.some((col) => col.columnDef.columnDefType === 'group') - ) { + if (columnOrder.length > 0 && !columns.some((col) => col.columnDef.columnDefType === "group")) { return [ ...getLeftLeafColumns(), ...Array.from(new Set(columnOrder)).map((colId) => - getCenterLeafColumns().find((col) => col?.id === colId), + getCenterLeafColumns().find((col) => col?.id === colId) ), ...getRightLeafColumns(), ].filter(Boolean); @@ -58,16 +51,14 @@ const DataTable_ShowHideColumnsMenu = ({ anchorEl, getRightLeafColumns(), ]); - const isNestedColumns = allColumns.some( - (col) => col.columnDef.columnDefType === 'group', - ); + const isNestedColumns = allColumns.some((col) => col.columnDef.columnDefType === "group"); const [hoveredColumn, setHoveredColumn] = useState(null); return ( {enableHiding && ( - )} {enableColumnOrdering && ( - )} {enableColumnPinning && ( - )} {enableHiding && ( - )} @@ -136,5 +112,5 @@ const DataTable_ShowHideColumnsMenu = ({ anchorEl, ))} ); -} -export default DataTable_ShowHideColumnsMenu \ No newline at end of file +}; +export default DataTable_ShowHideColumnsMenu; diff --git a/src/core/components/DataTable/menus/ShowHideColumnsMenuItems.js b/src/core/components/DataTable/menus/ShowHideColumnsMenuItems.js index 58425d9..97c2e5d 100644 --- a/src/core/components/DataTable/menus/ShowHideColumnsMenuItems.js +++ b/src/core/components/DataTable/menus/ShowHideColumnsMenuItems.js @@ -30,7 +30,7 @@ const DataTable_ShowHideColumnsMenuItems = ({ const switchChecked = column.getIsVisible(); const handleToggleColumnHidden = (column) => { - if (columnDefType === 'group') { + if (columnDefType === "group") { column?.columns?.forEach?.((childColumn) => { childColumn.toggleVisibility(!switchChecked); }); @@ -78,29 +78,29 @@ const DataTable_ShowHideColumnsMenuItems = ({ ref={menuItemRef} {...rest} sx={(theme) => ({ - alignItems: 'center', - justifyContent: 'flex-start', + alignItems: "center", + justifyContent: "flex-start", my: 0, opacity: isDragging ? 0.5 : 1, outline: isDragging ? `2px dashed ${theme.palette.grey[500]}` : hoveredColumn?.id === column.id - ? `2px dashed ${draggingBorderColor}` - : 'none', - outlineOffset: '-2px', + ? `2px dashed ${draggingBorderColor}` + : "none", + outlineOffset: "-2px", pl: `${(column.depth + 0.5) * 2}rem`, - py: '6px', - ...(parseFromValuesOrFunc(rest?.sx, theme)), + py: "6px", + ...parseFromValuesOrFunc(rest?.sx, theme), })} > - {columnDefType !== 'group' && + {columnDefType !== "group" && enableColumnOrdering && !isNestedColumns && (columnDef.enableColumnOrdering !== false ? ( @@ -110,7 +110,7 @@ const DataTable_ShowHideColumnsMenuItems = ({ table={table} /> ) : ( - + ))} {enableHiding ? ( + } @@ -136,9 +133,7 @@ const DataTable_ShowHideColumnsMenuItems = ({ onChange={() => handleToggleColumnHidden(column)} /> ) : ( - - {columnDef.header} - + {columnDef.header} )} @@ -155,6 +150,5 @@ const DataTable_ShowHideColumnsMenuItems = ({ ))} ); - -} -export default DataTable_ShowHideColumnsMenuItems; \ No newline at end of file +}; +export default DataTable_ShowHideColumnsMenuItems; diff --git a/src/core/components/DataTable/refactor/RefactorTable.jsx b/src/core/components/DataTable/refactor/RefactorTable.jsx index 71e302c..49217a0 100644 --- a/src/core/components/DataTable/refactor/RefactorTable.jsx +++ b/src/core/components/DataTable/refactor/RefactorTable.jsx @@ -1,14 +1,14 @@ -"use client" -import {IconButton, Tooltip} from '@mui/material'; -import RestartAltIcon from '@mui/icons-material/RestartAlt'; +"use client"; +import { IconButton, Tooltip } from "@mui/material"; +import RestartAltIcon from "@mui/icons-material/RestartAlt"; import useTableSetting from "@/lib/hooks/useTableSetting"; -import {useState} from "react"; +import { useState } from "react"; function RefactorTable() { - const {refactorAction} = useTableSetting(); + const { refactorAction } = useTableSetting(); const [userId, setUserId] = useState(0); - const [pageName, setPageName] = useState('testPage'); - const [tableName, setTableName] = useState('testTable'); + const [pageName, setPageName] = useState("testPage"); + const [tableName, setTableName] = useState("testTable"); const refactor = () => { refactorAction(userId, pageName, tableName); @@ -17,12 +17,10 @@ function RefactorTable() { return ( - + ); } export default RefactorTable; - - diff --git a/src/core/components/DataTable/table/Paper.js b/src/core/components/DataTable/table/Paper.js index 9a3be31..ede80b3 100644 --- a/src/core/components/DataTable/table/Paper.js +++ b/src/core/components/DataTable/table/Paper.js @@ -1,27 +1,27 @@ -import {parseFromValuesOrFunc} from "@/core/utils/utils"; -import {Paper} from "@mui/material"; +import { parseFromValuesOrFunc } from "@/core/utils/utils"; +import { Paper } from "@mui/material"; import DataTable_BottomToolbar from "../toolbar/BottomToolbar"; import DataTable_TopToolbar from "../toolbar/TopToolbar"; import DataTable_TableContainer from "./TableContainer"; -const DataTable_Paper = ({table, ...rest}) => { +const DataTable_Paper = ({ table, ...rest }) => { const { getState, options: { enableBottomToolbar, enableTopToolbar, - mrtTheme: {baseBackgroundColor}, + mrtTheme: { baseBackgroundColor }, muiTablePaperProps, renderBottomToolbar, renderTopToolbar, }, - refs: {tablePaperRef}, + refs: { tablePaperRef }, } = table; - const {isFullScreen} = getState(); + const { isFullScreen } = getState(); const paperProps = { - ...parseFromValuesOrFunc(muiTablePaperProps, {table}), + ...parseFromValuesOrFunc(muiTablePaperProps, { table }), ...rest, }; @@ -39,42 +39,44 @@ const DataTable_Paper = ({table, ...rest}) => { style={{ ...(isFullScreen ? { - bottom: 0, - height: '100dvh', - left: 0, - margin: 0, - maxHeight: '100dvh', - maxWidth: '100dvw', - padding: 0, - position: 'fixed', - right: 0, - top: 0, - width: '100dvw', - zIndex: 999, - } + bottom: 0, + height: "100dvh", + left: 0, + margin: 0, + maxHeight: "100dvh", + maxWidth: "100dvw", + padding: 0, + position: "fixed", + right: 0, + top: 0, + width: "100dvw", + zIndex: 999, + } : {}), ...paperProps?.style, }} sx={(theme) => ({ backgroundColor: baseBackgroundColor, - backgroundImage: 'unset', - overflow: 'hidden', - transition: 'all 100ms ease-in-out', - ...(parseFromValuesOrFunc(paperProps?.sx, theme)), + backgroundImage: "unset", + overflow: "hidden", + transition: "all 100ms ease-in-out", + ...parseFromValuesOrFunc(paperProps?.sx, theme), })} > {enableTopToolbar && - (parseFromValuesOrFunc(renderTopToolbar, {table}) ?? ( - + (parseFromValuesOrFunc(renderTopToolbar, { table }) ?? ( + ))} - + {enableBottomToolbar && - (parseFromValuesOrFunc(renderBottomToolbar, {table}) ?? ( - - ))} + (parseFromValuesOrFunc(renderBottomToolbar, { table }) ?? )} ); }; diff --git a/src/core/components/DataTable/table/Table.js b/src/core/components/DataTable/table/Table.js index ca49d0c..1bf6b69 100644 --- a/src/core/components/DataTable/table/Table.js +++ b/src/core/components/DataTable/table/Table.js @@ -5,10 +5,7 @@ import { useMemo } from "react"; import DataTable_TableBody, { Memo_DataTable_TableBody } from "../body/TableBody"; import DataTable_TableHead from "../head/TableHead"; -const DataTable_Table = ({ - table, - ...rest -}) => { +const DataTable_Table = ({ table, ...rest }) => { const { getFlatHeaders, getState, @@ -23,8 +20,7 @@ const DataTable_Table = ({ renderCaption, }, } = table; - const { columnSizing, columnSizingInfo, columnVisibility, isFullScreen } = - getState(); + const { columnSizing, columnSizingInfo, columnVisibility, isFullScreen } = getState(); const tableProps = { ...parseFromValuesOrFunc(muiTableProps, { table }), @@ -58,14 +54,14 @@ const DataTable_Table = ({ {...tableProps} style={{ ...columnSizeVars, ...tableProps?.style }} sx={(theme) => ({ - display: layoutMode?.startsWith('grid') ? 'grid' : undefined, - position: 'relative', - ...(parseFromValuesOrFunc(tableProps?.sx, theme)), + display: layoutMode?.startsWith("grid") ? "grid" : undefined, + position: "relative", + ...parseFromValuesOrFunc(tableProps?.sx, theme), })} > {!!Caption && {Caption}} {enableTableHead && } - {memoMode === 'table-body' || columnSizingInfo.isResizingColumn ? ( + {memoMode === "table-body" || columnSizingInfo.isResizingColumn ? ( ) : ( @@ -73,5 +69,5 @@ const DataTable_Table = ({ {/* {enableTableFooter && } */} ); -} -export default DataTable_Table \ No newline at end of file +}; +export default DataTable_Table; diff --git a/src/core/components/DataTable/table/TableContainer.js b/src/core/components/DataTable/table/TableContainer.js index aa4b625..bc1d80c 100644 --- a/src/core/components/DataTable/table/TableContainer.js +++ b/src/core/components/DataTable/table/TableContainer.js @@ -5,31 +5,17 @@ import DataTable_CellActionMenu from "../menus/CellActionMenu"; import DataTable_Table from "./Table"; import DataTable_TableLoadingOverlay from "./TableLoadingOverlay"; -const useIsomorphicLayoutEffect = - typeof window !== 'undefined' ? useLayoutEffect : useEffect; +const useIsomorphicLayoutEffect = typeof window !== "undefined" ? useLayoutEffect : useEffect; -const DataTable_TableContainer = ({ - table, - ...rest -}) => { +const DataTable_TableContainer = ({ table, ...rest }) => { const { getState, - options: { - enableCellActions, - enableStickyHeader, - muiTableContainerProps, - }, + options: { enableCellActions, enableStickyHeader, muiTableContainerProps }, refs: { bottomToolbarRef, tableContainerRef, topToolbarRef }, } = table; - const { - actionCell, - isFullScreen, - isLoading, - showLoadingOverlay, - } = getState(); + const { actionCell, isFullScreen, isLoading, showLoadingOverlay } = getState(); - const loading = - showLoadingOverlay !== false && (isLoading || showLoadingOverlay); + const loading = showLoadingOverlay !== false && (isLoading || showLoadingOverlay); const [totalToolbarHeight, setTotalToolbarHeight] = useState(0); @@ -41,15 +27,9 @@ const DataTable_TableContainer = ({ }; useIsomorphicLayoutEffect(() => { - const topToolbarHeight = - typeof document !== 'undefined' - ? topToolbarRef.current?.offsetHeight ?? 0 - : 0; + const topToolbarHeight = typeof document !== "undefined" ? topToolbarRef.current?.offsetHeight ?? 0 : 0; - const bottomToolbarHeight = - typeof document !== 'undefined' - ? bottomToolbarRef?.current?.offsetHeight ?? 0 - : 0; + const bottomToolbarHeight = typeof document !== "undefined" ? bottomToolbarRef?.current?.offsetHeight ?? 0 : 0; setTotalToolbarHeight(topToolbarHeight + bottomToolbarHeight); }); @@ -57,7 +37,7 @@ const DataTable_TableContainer = ({ return ( { if (node) { @@ -69,19 +49,17 @@ const DataTable_TableContainer = ({ } }} style={{ - maxHeight: isFullScreen - ? `calc(100vh - ${totalToolbarHeight}px)` - : undefined, + maxHeight: isFullScreen ? `calc(100vh - ${totalToolbarHeight}px)` : undefined, ...tableContainerProps?.style, }} sx={(theme) => ({ maxHeight: enableStickyHeader ? `clamp(350px, calc(100vh - ${totalToolbarHeight}px), 9999px)` : undefined, - maxWidth: '100%', - overflow: 'auto', - position: 'relative', - ...(parseFromValuesOrFunc(tableContainerProps?.sx, theme)), + maxWidth: "100%", + overflow: "auto", + position: "relative", + ...parseFromValuesOrFunc(tableContainerProps?.sx, theme), })} > {loading ? : null} @@ -89,6 +67,5 @@ const DataTable_TableContainer = ({ {enableCellActions && actionCell && } ); - -} -export default DataTable_TableContainer \ No newline at end of file +}; +export default DataTable_TableContainer; diff --git a/src/core/components/DataTable/table/TableLoadingOverlay.js b/src/core/components/DataTable/table/TableLoadingOverlay.js index 55e4ae5..0c417dd 100644 --- a/src/core/components/DataTable/table/TableLoadingOverlay.js +++ b/src/core/components/DataTable/table/TableLoadingOverlay.js @@ -1,9 +1,6 @@ import { Box, CircularProgress } from "@mui/material"; -const DataTable_TableLoadingOverlay = ({ - table, - ...rest -}) => { +const DataTable_TableLoadingOverlay = ({ table, ...rest }) => { const { options: { localization, @@ -20,17 +17,17 @@ const DataTable_TableLoadingOverlay = ({ return ( @@ -43,6 +40,5 @@ const DataTable_TableLoadingOverlay = ({ )} ); - -} -export default DataTable_TableLoadingOverlay \ No newline at end of file +}; +export default DataTable_TableLoadingOverlay; diff --git a/src/core/components/DataTable/toolbar/BottomToolbar.js b/src/core/components/DataTable/toolbar/BottomToolbar.js index 15e7f5a..ced2c06 100644 --- a/src/core/components/DataTable/toolbar/BottomToolbar.js +++ b/src/core/components/DataTable/toolbar/BottomToolbar.js @@ -3,23 +3,15 @@ import { Box, alpha, useMediaQuery } from "@mui/material"; import DataTable_LinearProgressBar from "./LinearProgressBar"; import DataTable_TablePagination from "./TablePagination"; -const DataTable_BottomToolbar = ({ - table, - ...rest -}) => { +const DataTable_BottomToolbar = ({ table, ...rest }) => { const { getState, - options: { - enablePagination, - muiBottomToolbarProps, - positionPagination, - renderBottomToolbarCustomActions, - }, + options: { enablePagination, muiBottomToolbarProps, positionPagination, renderBottomToolbarCustomActions }, refs: { bottomToolbarRef }, } = table; const { isFullScreen } = getState(); - const isMobile = useMediaQuery('(max-width:720px)'); + const isMobile = useMediaQuery("(max-width:720px)"); const toolbarProps = { ...parseFromValuesOrFunc(muiBottomToolbarProps, { table }), ...rest, @@ -40,49 +32,41 @@ const DataTable_BottomToolbar = ({ }} sx={(theme) => ({ ...getCommonToolbarStyles({ table, theme }), - bottom: isFullScreen ? '0' : undefined, - boxShadow: `0 1px 2px -1px ${alpha( - theme.palette.grey[700], - 0.5, - )} inset`, + bottom: isFullScreen ? "0" : undefined, + boxShadow: `0 1px 2px -1px ${alpha(theme.palette.grey[700], 0.5)} inset`, left: 0, - position: isFullScreen ? 'fixed' : 'relative', + position: isFullScreen ? "fixed" : "relative", right: 0, - ...(parseFromValuesOrFunc(toolbarProps?.sx, theme)), + ...parseFromValuesOrFunc(toolbarProps?.sx, theme), })} > - {renderBottomToolbarCustomActions ? ( - renderBottomToolbarCustomActions({ table }) - ) : ( - - )} + {renderBottomToolbarCustomActions ? renderBottomToolbarCustomActions({ table }) : } - {enablePagination && - ['both', 'bottom'].includes(positionPagination ?? '') && ( - - )} + {enablePagination && ["both", "bottom"].includes(positionPagination ?? "") && ( + + )} ); -} -export default DataTable_BottomToolbar \ No newline at end of file +}; +export default DataTable_BottomToolbar; diff --git a/src/core/components/DataTable/toolbar/LinearProgressBar.js b/src/core/components/DataTable/toolbar/LinearProgressBar.js index cdcbc0a..74c465f 100644 --- a/src/core/components/DataTable/toolbar/LinearProgressBar.js +++ b/src/core/components/DataTable/toolbar/LinearProgressBar.js @@ -1,11 +1,7 @@ import { parseFromValuesOrFunc } from "@/core/utils/utils"; import { Collapse, LinearProgress } from "@mui/material"; -const DataTable_LinearProgressBar = ({ - isTopToolbar, - table, - ...rest -}) => { +const DataTable_LinearProgressBar = ({ isTopToolbar, table, ...rest }) => { const { getState, options: { muiLinearProgressProps }, @@ -26,19 +22,19 @@ const DataTable_LinearProgressBar = ({ mountOnEnter sx={{ bottom: isTopToolbar ? 0 : undefined, - position: 'absolute', + position: "absolute", top: !isTopToolbar ? 0 : undefined, - width: '100%', + width: "100%", }} unmountOnExit > ); -} -export default DataTable_LinearProgressBar \ No newline at end of file +}; +export default DataTable_LinearProgressBar; diff --git a/src/core/components/DataTable/toolbar/TablePagination.js b/src/core/components/DataTable/toolbar/TablePagination.js index cd70fda..6492b41 100644 --- a/src/core/components/DataTable/toolbar/TablePagination.js +++ b/src/core/components/DataTable/toolbar/TablePagination.js @@ -1,16 +1,23 @@ import { flipIconStyles, getCommonTooltipProps, parseFromValuesOrFunc } from "@/core/utils/utils"; import { useTheme } from "@emotion/react"; -import { Box, IconButton, InputLabel, MenuItem, Pagination, PaginationItem, Select, Tooltip, Typography, useMediaQuery } from "@mui/material"; +import { + Box, + IconButton, + InputLabel, + MenuItem, + Pagination, + PaginationItem, + Select, + Tooltip, + Typography, + useMediaQuery, +} from "@mui/material"; const defaultRowsPerPage = [5, 10, 15, 20, 25, 30, 50, 100]; -const DataTable_TablePagination = ({ - position = 'bottom', - table, - ...rest -}) => { +const DataTable_TablePagination = ({ position = "bottom", table, ...rest }) => { const theme = useTheme(); - const isMobile = useMediaQuery('(max-width: 720px)'); + const isMobile = useMediaQuery("(max-width: 720px)"); const { getState, @@ -64,26 +71,21 @@ const DataTable_TablePagination = ({ {showRowsPerPage && ( - + {localization.rowsPerPage} @@ -92,22 +94,19 @@ const DataTable_TablePagination = ({ disableUnderline disabled={disabled} inputProps={{ - 'aria-label': localization.rowsPerPage, - id: 'mrt-rows-per-page', + "aria-label": localization.rowsPerPage, + id: "mrt-rows-per-page", }} label={localization.rowsPerPage} - onChange={(event) => - table.setPageSize(+(event.target.value)) - } + onChange={(event) => table.setPageSize(+event.target.value)} sx={{ mb: 0 }} value={pageSize} variant="standard" {...SelectProps} > {rowsPerPageOptions.map((option) => { - const value = typeof option !== 'number' ? option.value : option; - const label = - typeof option !== 'number' ? option.label : `${option}`; + const value = typeof option !== "number" ? option.value : option; + const label = typeof option !== "number" ? option.label : `${option}`; return ( SelectProps?.children ?? (SelectProps?.native ? ( @@ -124,7 +123,7 @@ const DataTable_TablePagination = ({ )} - {paginationDisplayMode === 'pages' ? ( + {paginationDisplayMode === "pages" ? ( - ) : paginationDisplayMode === 'default' ? ( + ) : paginationDisplayMode === "default" ? ( <> {`${lastRowIndex === 0 ? 0 : (firstRowIndex + 1).toLocaleString() - }-${lastRowIndex.toLocaleString()} ${localization.of - } ${totalRowCount.toLocaleString()}`} + >{`${ + lastRowIndex === 0 ? 0 : (firstRowIndex + 1).toLocaleString() + }-${lastRowIndex.toLocaleString()} ${ + localization.of + } ${totalRowCount.toLocaleString()}`} {showFirstButton && ( @@ -213,5 +214,5 @@ const DataTable_TablePagination = ({ ) : null} ); -} -export default DataTable_TablePagination \ No newline at end of file +}; +export default DataTable_TablePagination; diff --git a/src/core/components/DataTable/toolbar/ToolbarInternalButtons.js b/src/core/components/DataTable/toolbar/ToolbarInternalButtons.js index 606add0..9250b89 100644 --- a/src/core/components/DataTable/toolbar/ToolbarInternalButtons.js +++ b/src/core/components/DataTable/toolbar/ToolbarInternalButtons.js @@ -16,32 +16,29 @@ const DataTable_ToolbarInternalButtons = ({ table, ...rest }) => { }, } = table; - return ( ({ - alignItems: 'center', - display: 'flex', + alignItems: "center", + display: "flex", zIndex: 3, - ...(parseFromValuesOrFunc(rest?.sx, theme)), + ...parseFromValuesOrFunc(rest?.sx, theme), })} > {renderToolbarInternalActions?.({ table, }) ?? ( - <> - {enableFilters && - enableColumnFilters && - columnFilterDisplayMode !== 'popover' && ( - - )} - {(enableHiding || enableColumnOrdering || enableColumnPinning) && ( - - )} - - )} + <> + {enableFilters && enableColumnFilters && columnFilterDisplayMode !== "popover" && ( + + )} + {(enableHiding || enableColumnOrdering || enableColumnPinning) && ( + + )} + + )} ); -} -export default DataTable_ToolbarInternalButtons \ No newline at end of file +}; +export default DataTable_ToolbarInternalButtons; diff --git a/src/core/components/DataTable/toolbar/TopToolbar.js b/src/core/components/DataTable/toolbar/TopToolbar.js index 7a321e2..b0e5297 100644 --- a/src/core/components/DataTable/toolbar/TopToolbar.js +++ b/src/core/components/DataTable/toolbar/TopToolbar.js @@ -1,12 +1,12 @@ -import {getCommonToolbarStyles, parseFromValuesOrFunc} from "@/core/utils/utils"; -import {Box, useMediaQuery} from "@mui/material"; +import { getCommonToolbarStyles, parseFromValuesOrFunc } from "@/core/utils/utils"; +import { Box, useMediaQuery } from "@mui/material"; import DataTable_LinearProgressBar from "./LinearProgressBar"; import DataTable_TablePagination from "./TablePagination"; import DataTable_ToolbarInternalButtons from "./ToolbarInternalButtons"; import FilterColumn from "@/core/components/DataTable/filter"; import RefactorTable from "@/core/components/DataTable/refactor/RefactorTable"; -const DataTable_TopToolbar = ({table, columns, table_url, user_id, page_name, table_name}) => { +const DataTable_TopToolbar = ({ table, columns, table_url, user_id, page_name, table_name }) => { const { getState, options: { @@ -16,19 +16,16 @@ const DataTable_TopToolbar = ({table, columns, table_url, user_id, page_name, ta positionPagination, renderTopToolbarCustomActions, }, - refs: {topToolbarRef}, + refs: { topToolbarRef }, } = table; - const {isFullScreen, showGlobalFilter} = getState(); + const { isFullScreen, showGlobalFilter } = getState(); - const isMobile = useMediaQuery('(max-width:720px)'); - const isTablet = useMediaQuery('(max-width:1024px)'); + const isMobile = useMediaQuery("(max-width:720px)"); + const isTablet = useMediaQuery("(max-width:1024px)"); - const toolbarProps = parseFromValuesOrFunc(muiTopToolbarProps, {table}); + const toolbarProps = parseFromValuesOrFunc(muiTopToolbarProps, { table }); - const stackAlertBanner = - isMobile || - !!renderTopToolbarCustomActions || - (showGlobalFilter && isTablet); + const stackAlertBanner = isMobile || !!renderTopToolbarCustomActions || (showGlobalFilter && isTablet); return ( ({ - ...getCommonToolbarStyles({table, theme}), - position: isFullScreen ? 'sticky' : 'relative', - top: isFullScreen ? '0' : undefined, - ...(parseFromValuesOrFunc(toolbarProps?.sx, theme)), + ...getCommonToolbarStyles({ table, theme }), + position: isFullScreen ? "sticky" : "relative", + top: isFullScreen ? "0" : undefined, + ...parseFromValuesOrFunc(toolbarProps?.sx, theme), })} > - {renderTopToolbarCustomActions?.({table}) ?? } + {renderTopToolbarCustomActions?.({ table }) ?? } {enableToolbarInternalActions && ( - - - + + + )} - {enablePagination && - ['both', 'top'].includes(positionPagination ?? '') && ( - - )} - + {enablePagination && ["both", "top"].includes(positionPagination ?? "") && ( + + )} + ); -} +}; -export default DataTable_TopToolbar \ No newline at end of file +export default DataTable_TopToolbar; diff --git a/src/core/components/NotificationDesign/AskForKeep.jsx b/src/core/components/NotificationDesign/AskForKeep.jsx index 7a68d2f..d4721bb 100644 --- a/src/core/components/NotificationDesign/AskForKeep.jsx +++ b/src/core/components/NotificationDesign/AskForKeep.jsx @@ -1,47 +1,61 @@ -'use client' +"use client"; -import SaveIcon from '@mui/icons-material/Save'; -import {Box, Button, Typography} from "@mui/material"; -import DownloadIcon from '@mui/icons-material/Download'; -import {toast} from "react-toastify"; - -function AskForKeep({onSaveFilter}) { +import SaveIcon from "@mui/icons-material/Save"; +import { Box, Button, Typography } from "@mui/material"; +import DownloadIcon from "@mui/icons-material/Download"; +import { toast } from "react-toastify"; +function AskForKeep({ onSaveFilter }) { const handleDismiss = () => { - toast.dismiss({containerId: "filtering"}); + toast.dismiss({ containerId: "filtering" }); }; return ( - - - + + + ذخیره سازی اطلاعات - + - - - آیا مایل به ذخیره فیلتر های اعمال شده برای دفعات بعد هستید؟ - + + آیا مایل به ذخیره فیلتر های اعمال شده برای دفعات بعد هستید؟ - - - + + + ); } -export default AskForKeep; \ No newline at end of file +export default AskForKeep; diff --git a/src/core/components/SidebarListItems.jsx b/src/core/components/SidebarListItems.jsx index d300d7f..050d9a6 100644 --- a/src/core/components/SidebarListItems.jsx +++ b/src/core/components/SidebarListItems.jsx @@ -1,77 +1,53 @@ import SidebarSubitems from "@/core/components/SidebarSubitems"; import { ExpandLess, ExpandMore } from "@mui/icons-material"; -import { - Collapse, - List, - ListItem, - ListItemButton, - ListItemIcon, - ListItemText, -} from "@mui/material"; +import { Collapse, List, ListItem, ListItemButton, ListItemIcon, ListItemText } from "@mui/material"; import Link from "next/link"; const SidebarListItems = ({ menuItem, dispatch }) => { - return ( - <> - - { - dispatch({ type: "COLLAPSE_MENU", id: menuItem.id }); - }} - > - - {menuItem.icon} - - - {menuItem.hasSubitems ? ( - menuItem.showSubitems ? ( - - ) : ( - - ) - ) : null} - - - - {menuItem.hasSubitems ? ( - - {menuItem.Subitems.map((subitem, index) => { - return ( - - ); - })} - - ) : null} - - - ); + return ( + <> + + { + dispatch({ type: "COLLAPSE_MENU", id: menuItem.id }); + }} + > + + {menuItem.icon} + + + {menuItem.hasSubitems ? menuItem.showSubitems ? : : null} + + + + {menuItem.hasSubitems ? ( + + {menuItem.Subitems.map((subitem, index) => { + return ; + })} + + ) : null} + + + ); }; export default SidebarListItems; diff --git a/src/core/components/SidebarMenu.jsx b/src/core/components/SidebarMenu.jsx index c9f6a73..0ad01dc 100644 --- a/src/core/components/SidebarMenu.jsx +++ b/src/core/components/SidebarMenu.jsx @@ -6,127 +6,119 @@ import { useEffect, useReducer, useState } from "react"; import { pageMenu } from "../utils/pageMenu"; function reducer(state, action) { - switch (action.type) { - case "COLLAPSE_MENU": - return state.map((item) => - action.id == item.id - ? { - ...item, - showSubitems: !item.showSubitems, - } - : item - ); - case "COLLAPSE_SUB_ITEMS": - return state.map((item) => { - return item.hasSubitems - ? { - ...item, - Subitems: item.Subitems.map((subitem) => - action.id === subitem.id - ? { - ...subitem, - showSubitems: !subitem.showSubitems, - } - : subitem - ), - } - : item; - }); - case "COLLAPSE_SUB_SECOND_ITEMS": - return state.map((item) => { - return item.hasSubitems - ? { - ...item, - Subitems: item.Subitems.map((subitem) => { - return subitem.hasSubitems - ? { - ...subitem, - Subitems: subitem.Subitems.map((secondSubitem) => - action.id === secondSubitem.id - ? { - ...secondSubitem, - showSubitems: !secondSubitem.showSubitems, - } - : secondSubitem - ), - } - : subitem; - }), - } - : item; - }); - case "SELECTED": - return state.map((item) => { - return item.type === "page" - ? { - ...item, - selected: action.route === item.route, - showSubitems: item.route === action.route, - } - : item.Subitems && Array.isArray(item.Subitems) - ? { - ...item, - Subitems: item.Subitems.map((subitem) => { - return subitem.type === "page" - ? { - ...subitem, - selected: action.route === subitem.route, - showSubitems: subitem.route === action.route, - } - : subitem.Subitems && Array.isArray(subitem.Subitems) - ? { - ...subitem, - Subitems: subitem.Subitems.map((secondSubItem) => ({ - ...secondSubItem, - selected: secondSubItem.route === action.route, - })), - showSubitems: subitem.Subitems.some( - (secondSubItem) => secondSubItem.route === action.route - ), - } - : subitem; - }), - showSubitems: item.Subitems.some( - (subitem) => subitem.showSubitems - ), - } - : item; - }); + switch (action.type) { + case "COLLAPSE_MENU": + return state.map((item) => + action.id == item.id + ? { + ...item, + showSubitems: !item.showSubitems, + } + : item + ); + case "COLLAPSE_SUB_ITEMS": + return state.map((item) => { + return item.hasSubitems + ? { + ...item, + Subitems: item.Subitems.map((subitem) => + action.id === subitem.id + ? { + ...subitem, + showSubitems: !subitem.showSubitems, + } + : subitem + ), + } + : item; + }); + case "COLLAPSE_SUB_SECOND_ITEMS": + return state.map((item) => { + return item.hasSubitems + ? { + ...item, + Subitems: item.Subitems.map((subitem) => { + return subitem.hasSubitems + ? { + ...subitem, + Subitems: subitem.Subitems.map((secondSubitem) => + action.id === secondSubitem.id + ? { + ...secondSubitem, + showSubitems: !secondSubitem.showSubitems, + } + : secondSubitem + ), + } + : subitem; + }), + } + : item; + }); + case "SELECTED": + return state.map((item) => { + return item.type === "page" + ? { + ...item, + selected: action.route === item.route, + showSubitems: item.route === action.route, + } + : item.Subitems && Array.isArray(item.Subitems) + ? { + ...item, + Subitems: item.Subitems.map((subitem) => { + return subitem.type === "page" + ? { + ...subitem, + selected: action.route === subitem.route, + showSubitems: subitem.route === action.route, + } + : subitem.Subitems && Array.isArray(subitem.Subitems) + ? { + ...subitem, + Subitems: subitem.Subitems.map((secondSubItem) => ({ + ...secondSubItem, + selected: secondSubItem.route === action.route, + })), + showSubitems: subitem.Subitems.some( + (secondSubItem) => secondSubItem.route === action.route + ), + } + : subitem; + }), + showSubitems: item.Subitems.some((subitem) => subitem.showSubitems), + } + : item; + }); - default: - throw new Error(); - } + default: + throw new Error(); + } } const SidebarMenu = () => { - const [menuItems, dispatch] = useReducer(reducer, pageMenu); - const pathname = usePathname(); - const [selectedKey, setSelectedKey] = useState(null); - useEffect(() => { - dispatch({ type: "SELECTED", route: pathname }); - setSelectedKey(pathname); - }, [pathname]); + const [menuItems, dispatch] = useReducer(reducer, pageMenu); + const pathname = usePathname(); + const [selectedKey, setSelectedKey] = useState(null); + useEffect(() => { + dispatch({ type: "SELECTED", route: pathname }); + setSelectedKey(pathname); + }, [pathname]); - useEffect(() => { - selectedKey && - document.querySelector(`[data-route="${selectedKey}"]`)?.scrollIntoView({ - behavior: "smooth", - block: "center", - }); - }, [selectedKey]); + useEffect(() => { + selectedKey && + document.querySelector(`[data-route="${selectedKey}"]`)?.scrollIntoView({ + behavior: "smooth", + block: "center", + }); + }, [selectedKey]); - return ( - - {menuItems.map((menuItem) => { - return ( - - ); - })} - - ); + return ( + + {menuItems.map((menuItem) => { + return ; + })} + + ); }; export default SidebarMenu; diff --git a/src/core/components/SidebarSubitems.jsx b/src/core/components/SidebarSubitems.jsx index b54d3a9..69418ea 100644 --- a/src/core/components/SidebarSubitems.jsx +++ b/src/core/components/SidebarSubitems.jsx @@ -1,75 +1,51 @@ import { ExpandLess, ExpandMore } from "@mui/icons-material"; -import { - Collapse, - List, - ListItem, - ListItemButton, - ListItemIcon, - ListItemText, -} from "@mui/material"; +import { Collapse, List, ListItem, ListItemButton, ListItemIcon, ListItemText } from "@mui/material"; import Link from "next/link"; const SidebarSubitems = ({ subitem, dispatch }) => { - return ( - <> - - { - dispatch({ type: "COLLAPSE_SUB_ITEMS", id: subitem.id }); - }} - > - - {subitem.icon} - - - {subitem.hasSubitems ? ( - subitem.showSubitems ? ( - - ) : ( - - ) - ) : null} - - - - {subitem.hasSubitems ? ( - - {subitem.Subitems.map((subSubitem, index) => { - return ( - - ); - })} - - ) : null} - - - ); + return ( + <> + + { + dispatch({ type: "COLLAPSE_SUB_ITEMS", id: subitem.id }); + }} + > + + {subitem.icon} + + + {subitem.hasSubitems ? subitem.showSubitems ? : : null} + + + + {subitem.hasSubitems ? ( + + {subitem.Subitems.map((subSubitem, index) => { + return ; + })} + + ) : null} + + + ); }; export default SidebarSubitems; diff --git a/src/core/components/Toasts/error.jsx b/src/core/components/Toasts/error.jsx index d0d9760..e93138b 100644 --- a/src/core/components/Toasts/error.jsx +++ b/src/core/components/Toasts/error.jsx @@ -3,189 +3,185 @@ import { Box, Typography } from "@mui/material"; import { Dangerous } from "@mui/icons-material"; export const errorServerToast = (toastContainer) => - toast.error( - () => ( - - - - - - {"The request failed due to an internal error."} - - - - - ), - { - icon: false, - containerId: toastContainer, - autoClose: 5000, - hideProgressBar: true, - pauseOnHover: true, - closeOnClick: false, - draggable: true, - } - ); + toast.error( + () => ( + + + + + {"The request failed due to an internal error."} + + + + ), + { + icon: false, + containerId: toastContainer, + autoClose: 5000, + hideProgressBar: true, + pauseOnHover: true, + closeOnClick: false, + draggable: true, + } + ); export const errorUnauthorizedToast = (toastContainer) => - toast.error( - () => ( - - - - - - {"The user is not authorized to make the request."} - - - - - ), - { - icon: false, - containerId: toastContainer, - autoClose: 3000, - hideProgressBar: true, - pauseOnHover: true, - closeOnClick: false, - draggable: true, - } - ); + toast.error( + () => ( + + + + + {"The user is not authorized to make the request."} + + + + ), + { + icon: false, + containerId: toastContainer, + autoClose: 3000, + hideProgressBar: true, + pauseOnHover: true, + closeOnClick: false, + draggable: true, + } + ); export const errorLogicToast = (message, toastContainer) => - toast.error( - () => ( - - - - - - {message || - "The request was well-formed but was unable to be followed due to semantic errors."} - - - - - ), - { - icon: false, - containerId: toastContainer, - autoClose: false, - closeOnClick: false, - draggable: false, - } - ); + toast.error( + () => ( + + + + + + {message || + "The request was well-formed but was unable to be followed due to semantic errors."} + + + + + ), + { + icon: false, + containerId: toastContainer, + autoClose: false, + closeOnClick: false, + draggable: false, + } + ); export const errorValidationToast = (message, toastContainer) => - toast.error( - () => ( - - - - - - {message || - "The request was well-formed but was unable to be followed due to semantic errors."} - - - - - ), - { - icon: false, - containerId: toastContainer, - autoClose: false, - closeOnClick: false, - draggable: false, - } - ); + toast.error( + () => ( + + + + + + {message || + "The request was well-formed but was unable to be followed due to semantic errors."} + + + + + ), + { + icon: false, + containerId: toastContainer, + autoClose: false, + closeOnClick: false, + draggable: false, + } + ); export const errorTooManyToast = (toastContainer) => - toast.error( - () => ( - - - - - - {"Too many requests have been sent within a given time span."} - - - - - ), - { - icon: false, - containerId: toastContainer, - autoClose: false, - closeOnClick: false, - draggable: false, - } - ); + toast.error( + () => ( + + + + + + {"Too many requests have been sent within a given time span."} + + + + + ), + { + icon: false, + containerId: toastContainer, + autoClose: false, + closeOnClick: false, + draggable: false, + } + ); export const errorClientToast = (toastContainer) => - toast.error( - () => ( - - - - - - { - "The API request is invalid or improperly formed. Consequently, the API server could not understand the request." - } - - - - - ), - { - icon: false, - containerId: toastContainer, - autoClose: false, - closeOnClick: false, - draggable: false, - } - ); + toast.error( + () => ( + + + + + + { + "The API request is invalid or improperly formed. Consequently, the API server could not understand the request." + } + + + + + ), + { + icon: false, + containerId: toastContainer, + autoClose: false, + closeOnClick: false, + draggable: false, + } + ); diff --git a/src/core/components/Toasts/success.jsx b/src/core/components/Toasts/success.jsx index b405a04..36023c6 100644 --- a/src/core/components/Toasts/success.jsx +++ b/src/core/components/Toasts/success.jsx @@ -3,33 +3,31 @@ import { Box, Typography } from "@mui/material"; import { Beenhere } from "@mui/icons-material"; export const successToast = (toastContainer) => - toast.success( - () => ( - - - - - - {"Your operation was successful"} - - - - - ), - { - icon: false, - containerId: toastContainer, - autoClose: 3000, - hideProgressBar: true, - pauseOnHover: true, - closeOnClick: false, - draggable: true, - } - ); + toast.success( + () => ( + + + + + {"Your operation was successful"} + + + + ), + { + icon: false, + containerId: toastContainer, + autoClose: 3000, + hideProgressBar: true, + pauseOnHover: true, + closeOnClick: false, + draggable: true, + } + ); diff --git a/src/core/middlewares/withAuth.js b/src/core/middlewares/withAuth.js index 1b93025..216b55b 100644 --- a/src/core/middlewares/withAuth.js +++ b/src/core/middlewares/withAuth.js @@ -1,22 +1,22 @@ -'use client' +"use client"; import { useAuth } from "@/lib/contexts/auth"; import { usePathname, useRouter } from "next/navigation"; import { useEffect } from "react"; function WithAuthMiddleware({ children }) { - const router = useRouter() - const pathName = usePathname() + const router = useRouter(); + const pathName = usePathname(); const { isAuth, initAuthState } = useAuth(); useEffect(() => { - if (!initAuthState) return + if (!initAuthState) return; if (!isAuth) { - router.replace(`${process.env.NEXT_PUBLIC_API_URL}/login?_back=${encodeURIComponent(pathName)}`) + router.replace(`${process.env.NEXT_PUBLIC_API_URL}/login?_back=${encodeURIComponent(pathName)}`); } - }, [isAuth, initAuthState]) + }, [isAuth, initAuthState]); if (!initAuthState || !isAuth) return null; - return <>{children} + return <>{children}; } -export default WithAuthMiddleware \ No newline at end of file +export default WithAuthMiddleware; diff --git a/src/core/utils/cacheRtl.js b/src/core/utils/cacheRtl.js index bf8c809..1393e2e 100644 --- a/src/core/utils/cacheRtl.js +++ b/src/core/utils/cacheRtl.js @@ -1,16 +1,16 @@ -'use client' +"use client"; import createCache from "@emotion/cache"; -import {prefixer} from "stylis"; +import { prefixer } from "stylis"; import stylisRTLPlugin from "stylis-plugin-rtl"; -import {CacheProvider} from "@emotion/react"; +import { CacheProvider } from "@emotion/react"; const cache = createCache({ - key: 'mui-rtl', + key: "mui-rtl", stylisPlugins: [prefixer, stylisRTLPlugin], }); const cacheProviderRtl = (props) => { return {props.children}; -} +}; -export default cacheProviderRtl \ No newline at end of file +export default cacheProviderRtl; diff --git a/src/core/utils/errorResponse.js b/src/core/utils/errorResponse.js index 3accb8f..1802581 100644 --- a/src/core/utils/errorResponse.js +++ b/src/core/utils/errorResponse.js @@ -1,4 +1,4 @@ -'use client' +"use client"; import { toast } from "react-toastify"; import { errorClientToast, @@ -6,56 +6,55 @@ import { errorServerToast, errorTooManyToast, errorUnauthorizedToast, - errorValidationToast + errorValidationToast, } from "@/core/components/toasts/error"; -const isServerError = status => status >= 500 && status <= 599; -const isClientError = status => status >= 400 && status <= 499; +const isServerError = (status) => status >= 500 && status <= 599; +const isClientError = (status) => status >= 400 && status <= 499; const errorServer = (response, notification, toastContainer) => { - if (notification) errorServerToast(toastContainer) -} + if (notification) errorServerToast(toastContainer); +}; const errorClient = (response, notification, toastContainer) => { switch (response.status) { case 401: - if (notification) errorUnauthorizedToast(toastContainer) + if (notification) errorUnauthorizedToast(toastContainer); break; case 422: - if ('type' in response.data) { + if ("type" in response.data) { if (Array.isArray(response.data.message)) { response.data.message.map((item) => { - if (notification) errorLogicToast(item, toastContainer) - }) + if (notification) errorLogicToast(item, toastContainer); + }); } else { - if (notification) errorLogicToast(response.data.message, toastContainer) + if (notification) errorLogicToast(response.data.message, toastContainer); } break; } if (notification) { - const errorsMap = Object.keys(response.data.errors) - const errorsArray = response.data.errors + const errorsMap = Object.keys(response.data.errors); + const errorsArray = response.data.errors; errorsMap.map((item, index) => { errorValidationToast(errorsArray[item][0], toastContainer); - }) - + }); } break; case 429: - if (notification) errorTooManyToast(toastContainer) - break + if (notification) errorTooManyToast(toastContainer); + break; default: - if (notification) errorClientToast(toastContainer) - break + if (notification) errorClientToast(toastContainer); + break; } -} +}; export const errorResponse = (response, notification, toastContainer) => { - if (notification) toast.dismiss({ container: toastContainer }) + if (notification) toast.dismiss({ container: toastContainer }); if (isServerError(response.status)) { - errorServer(response, notification, toastContainer) + errorServer(response, notification, toastContainer); } else if (isClientError(response.status)) { - errorClient(response, notification, toastContainer) + errorClient(response, notification, toastContainer); } -} +}; diff --git a/src/core/utils/flattenArrayOfObjects.js b/src/core/utils/flattenArrayOfObjects.js index 4dd4612..5b1564c 100644 --- a/src/core/utils/flattenArrayOfObjects.js +++ b/src/core/utils/flattenArrayOfObjects.js @@ -7,4 +7,4 @@ export const flattenArrayOfObjects = (array, key) => { } return acc; }, []); -}; \ No newline at end of file +}; diff --git a/src/core/utils/pageMenu.js b/src/core/utils/pageMenu.js index 81cb873..6145ffd 100644 --- a/src/core/utils/pageMenu.js +++ b/src/core/utils/pageMenu.js @@ -2,346 +2,346 @@ import { AirlineSeatReclineNormal, Assessment, Repartition, Security, SpaceDashb export const pageMenu = [ { - id: 'dashboard', - label: 'پیشخوان', + id: "dashboard", + label: "پیشخوان", type: "page", route: "/dashboard", - icon: , + icon: , }, { - id: 'userManagement', - label: 'مدیریت کاربران', + id: "userManagement", + label: "مدیریت کاربران", type: "page", route: process.env.NEXT_PUBLIC_API_URL + "/v2/user_management", - icon: , + icon: , }, { - id: 'projectsManagment', - label: 'پروژه های راهداری', + id: "projectsManagment", + label: "پروژه های راهداری", type: "menu", - icon: , + icon: , hasSubitems: true, Subitems: [ { - id: 'projectsManagmentFinance', - label: 'ثبت قرارداد و پروژه', + id: "projectsManagmentFinance", + label: "ثبت قرارداد و پروژه", type: "page", route: process.env.NEXT_PUBLIC_API_URL + "/v2/rahdari_projects/finance", - icon: , + icon: , }, { - id: 'projectsManagmentList', - label: 'لیست پروژه ها', + id: "projectsManagmentList", + label: "لیست پروژه ها", type: "page", route: process.env.NEXT_PUBLIC_API_URL + "/v2/rahdari_projects/projects_list", - icon: , + icon: , }, { - id: 'projectsManagmentProposal', - label: 'پروژه های پیشنهادی', + id: "projectsManagmentProposal", + label: "پروژه های پیشنهادی", type: "page", route: process.env.NEXT_PUBLIC_API_URL + "/v2/rahdari_projects/proposal", - icon: , + icon: , }, { - id: 'projectsManagmentLawmaker', - label: 'درخواست نمایندگان', + id: "projectsManagmentLawmaker", + label: "درخواست نمایندگان", type: "page", route: process.env.NEXT_PUBLIC_API_URL + "/v2/rahdari_projects/lawmakers", - icon: , + icon: , }, { - id: 'projectsManagmentMap', - label: 'پراکندگی بر روی نقشه', + id: "projectsManagmentMap", + label: "پراکندگی بر روی نقشه", type: "page", route: process.env.NEXT_PUBLIC_API_URL + "/v2/map?type=rahdari_projects", - icon: , + icon: , }, - ] + ], }, { - id: 'roadItemManagment', - label: 'فعالیت های روزانه', + id: "roadItemManagment", + label: "فعالیت های روزانه", type: "menu", - icon: , + icon: , hasSubitems: true, Subitems: [ { - id: 'roadItemManagmentSupervisor', - label: 'ارزیابی', + id: "roadItemManagmentSupervisor", + label: "ارزیابی", type: "menu", - icon: , + icon: , hasSubitems: true, Subitems: [ { - id: 'roadItemManagmentSupervisorCartable', - label: 'کارتابل', + id: "roadItemManagmentSupervisorCartable", + label: "کارتابل", type: "page", route: process.env.NEXT_PUBLIC_API_URL + "/v2/road_items/supervisor/cartable", }, - ] + ], }, { - id: 'roadItemManagmentOparation', - label: 'عملیات', + id: "roadItemManagmentOparation", + label: "عملیات", type: "menu", - icon: , + icon: , hasSubitems: true, Subitems: [ { - id: 'roadItemManagmentOparationCreate', - label: 'ثبت فعالیت', + id: "roadItemManagmentOparationCreate", + label: "ثبت فعالیت", type: "page", route: process.env.NEXT_PUBLIC_API_URL + "/v2/road_items/operator/create", }, { - id: 'roadItemManagmentOparationCartable', - label: 'کارتابل', + id: "roadItemManagmentOparationCartable", + label: "کارتابل", type: "page", route: process.env.NEXT_PUBLIC_API_URL + "/v2/road_items/operator/cartable", }, - ] + ], }, { - id: 'roadItemManagmentMap', - label: 'پراکندگی بر روی نقشه', + id: "roadItemManagmentMap", + label: "پراکندگی بر روی نقشه", type: "page", route: process.env.NEXT_PUBLIC_API_URL + "/v2/map?type=road_items", - icon: , + icon: , }, { - id: 'roadItemManagmentReport', - label: 'گزارش ها', + id: "roadItemManagmentReport", + label: "گزارش ها", type: "page", route: process.env.NEXT_PUBLIC_API_URL + "/v2/road_items/report", - icon: , + icon: , }, - ] + ], }, { - id: 'roadPatrolManagment', - label: 'گشت راهداری و ترابری', + id: "roadPatrolManagment", + label: "گشت راهداری و ترابری", type: "menu", - icon: , + icon: , hasSubitems: true, Subitems: [ { - id: 'roadPatrolManagmentSupervisor', - label: 'ارزیابی', + id: "roadPatrolManagmentSupervisor", + label: "ارزیابی", type: "menu", - icon: , + icon: , hasSubitems: true, Subitems: [ { - id: 'roadPatrolManagmentSupervisorCartable', - label: 'کارتابل', + id: "roadPatrolManagmentSupervisorCartable", + label: "کارتابل", type: "page", route: process.env.NEXT_PUBLIC_API_URL + "/road_patrols/supervisor/cartable", }, - ] + ], }, { - id: 'roadPatrolManagmentOparation', - label: 'عملیات', + id: "roadPatrolManagmentOparation", + label: "عملیات", type: "menu", - icon: , + icon: , hasSubitems: true, Subitems: [ { - id: 'roadPatrolManagmentOparationCreate', - label: 'ثبت اقدام', + id: "roadPatrolManagmentOparationCreate", + label: "ثبت اقدام", type: "page", route: process.env.NEXT_PUBLIC_API_URL + "/v2/road_patrols/operator/create", }, { - id: 'roadPatrolManagmentOparationCartable', - label: 'کارتابل', + id: "roadPatrolManagmentOparationCartable", + label: "کارتابل", type: "page", route: process.env.NEXT_PUBLIC_API_URL + "/v2/road_patrols/operator/cartable", }, - ] + ], }, { - id: 'roadPatrolManagmentMap', - label: 'پراکندگی بر روی نقشه', + id: "roadPatrolManagmentMap", + label: "پراکندگی بر روی نقشه", type: "page", route: process.env.NEXT_PUBLIC_API_URL + "/v2/map?type=road_patrols", - icon: , + icon: , }, { - id: 'roadPatrolManagmentReport', - label: 'گزارش ها', + id: "roadPatrolManagmentReport", + label: "گزارش ها", type: "page", route: process.env.NEXT_PUBLIC_API_URL + "/v2/road_patrols/report", - icon: , + icon: , }, - ] + ], }, { - id: 'safetyAndPrivacyManagment', - label: 'نگهداری حریم راه', + id: "safetyAndPrivacyManagment", + label: "نگهداری حریم راه", type: "menu", - icon: , + icon: , hasSubitems: true, Subitems: [ { - id: 'safetyAndPrivacyManagmentOparation', - label: 'عملیات', + id: "safetyAndPrivacyManagmentOparation", + label: "عملیات", type: "menu", - icon: , + icon: , hasSubitems: true, Subitems: [ { - id: 'safetyAndPrivacyManagmentOparationCreate', - label: 'ثبت فعالیت', + id: "safetyAndPrivacyManagmentOparationCreate", + label: "ثبت فعالیت", type: "page", route: process.env.NEXT_PUBLIC_API_URL + "/safety_and_privacy/operator/first_step", }, { - id: 'safetyAndPrivacyManagmentOparationCartable', - label: 'کارتابل', + id: "safetyAndPrivacyManagmentOparationCartable", + label: "کارتابل", type: "page", route: process.env.NEXT_PUBLIC_API_URL + "/v2/safety_and_privacy/operator/cartable", }, - ] + ], }, { - id: 'safetyAndPrivacyManagmentMap', - label: 'پراکندگی بر روی نقشه', + id: "safetyAndPrivacyManagmentMap", + label: "پراکندگی بر روی نقشه", type: "page", route: process.env.NEXT_PUBLIC_API_URL + "/v2/map?type=safety_and_privacy", - icon: , + icon: , }, { - id: 'safetyAndPrivacyManagmentReport', - label: 'گزارش ها', + id: "safetyAndPrivacyManagmentReport", + label: "گزارش ها", type: "page", route: process.env.NEXT_PUBLIC_API_URL + "/v2/safety_and_privacy/report", - icon: , + icon: , }, - ] + ], }, { - id: 'roadObservationsManagment', - label: 'واکنش سریع', + id: "roadObservationsManagment", + label: "واکنش سریع", type: "menu", - icon: , + icon: , hasSubitems: true, Subitems: [ { - id: 'roadObservationsManagmentSupervisor', - label: 'ارزیابی', + id: "roadObservationsManagmentSupervisor", + label: "ارزیابی", type: "menu", - icon: , + icon: , hasSubitems: true, Subitems: [ { - id: 'roadObservationsManagmentSupervisorCartable', - label: 'کارتابل', + id: "roadObservationsManagmentSupervisorCartable", + label: "کارتابل", type: "page", route: process.env.NEXT_PUBLIC_API_URL + "/v2/road_observations/supervisor/cartable", }, - ] + ], }, { - id: 'roadObservationsManagmentList', - label: 'رسیدگی به شکایات', + id: "roadObservationsManagmentList", + label: "رسیدگی به شکایات", type: "page", route: process.env.NEXT_PUBLIC_API_URL + "/v2/road_observations", - icon: , + icon: , }, { - id: 'roadObservationsManagmentOparation', - label: 'عملیات', + id: "roadObservationsManagmentOparation", + label: "عملیات", type: "menu", - icon: , + icon: , hasSubitems: true, Subitems: [ { - id: 'roadObservationsManagmentOparationCartable', - label: 'کارتابل', + id: "roadObservationsManagmentOparationCartable", + label: "کارتابل", type: "page", route: process.env.NEXT_PUBLIC_API_URL + "/v2/road_observations/operator/cartable", }, - ] + ], }, { - id: 'roadObservationsManagmentMap', - label: 'پراکندگی بر روی نقشه', + id: "roadObservationsManagmentMap", + label: "پراکندگی بر روی نقشه", type: "page", route: process.env.NEXT_PUBLIC_API_URL + "/v2/map?type=road_observations", - icon: , + icon: , }, { - id: 'roadObservationsManagmentReport', - label: 'گزارش ها', + id: "roadObservationsManagmentReport", + label: "گزارش ها", type: "page", route: process.env.NEXT_PUBLIC_API_URL + "/v2/road_observations/report/index", - icon: , + icon: , }, - ] + ], }, { - id: 'winterCampManagment', - label: 'قرارگاه زمستانی', + id: "winterCampManagment", + label: "قرارگاه زمستانی", type: "menu", - icon: , + icon: , hasSubitems: true, Subitems: [ { - id: 'winterCampManagmentBlocking', - label: 'محور های انسدادی', + id: "winterCampManagmentBlocking", + label: "محور های انسدادی", type: "page", route: process.env.NEXT_PUBLIC_API_URL + "/v2/winter_camp", - icon: , + icon: , }, { - id: 'winterCampManagmentFirstRing', - label: 'محور های حلقه اول', + id: "winterCampManagmentFirstRing", + label: "محور های حلقه اول", type: "page", route: process.env.NEXT_PUBLIC_API_URL + "/v2/map?type=camp", - icon: , + icon: , }, { - id: 'winterCampManagmentReport', - label: 'گزارش ها', + id: "winterCampManagmentReport", + label: "گزارش ها", type: "page", route: process.env.NEXT_PUBLIC_API_URL + "/v2/map?type=campNew", - icon: , + icon: , }, - ] + ], }, { - id: 'receiptManagment', - label: 'خسارات وارده بر ابنیه فنی و تاسیسات راه', + id: "receiptManagment", + label: "خسارات وارده بر ابنیه فنی و تاسیسات راه", type: "menu", - icon: , + icon: , hasSubitems: true, Subitems: [ { - id: 'receiptManagmentOparation', - label: 'عملیات', + id: "receiptManagmentOparation", + label: "عملیات", type: "menu", - icon: , + icon: , hasSubitems: true, Subitems: [ { - id: 'receiptManagmentOparationCartable', - label: 'کارتابل', + id: "receiptManagmentOparationCartable", + label: "کارتابل", type: "page", route: process.env.NEXT_PUBLIC_API_URL + "/v2/receipt", }, - ] + ], }, { - id: 'receiptManagmentReport', - label: 'گزارش ها', + id: "receiptManagmentReport", + label: "گزارش ها", type: "page", route: process.env.NEXT_PUBLIC_API_URL + "/v2/receipt/report", - icon: , + icon: , }, - ] - } + ], + }, // { // id: "hello", // type: "menu", @@ -383,4 +383,4 @@ export const pageMenu = [ // hasSubitems: true, // showSubitems: false // }, -] \ No newline at end of file +]; diff --git a/src/core/utils/routes.js b/src/core/utils/routes.js index 39b6b09..8fae96f 100644 --- a/src/core/utils/routes.js +++ b/src/core/utils/routes.js @@ -1,4 +1,4 @@ -const api = process.env.NEXT_PUBLIC_API_URL +const api = process.env.NEXT_PUBLIC_API_URL; -export const GET_USER_ROUTE = api + '/webapi/user/get-permission' -export const GET_LOGIN_ROUTE = api + '/test_login' \ No newline at end of file +export const GET_USER_ROUTE = api + "/webapi/user/get-permission"; +export const GET_LOGIN_ROUTE = api + "/login_dev"; diff --git a/src/core/utils/successRequest.js b/src/core/utils/successRequest.js index 5138d7a..d23776a 100644 --- a/src/core/utils/successRequest.js +++ b/src/core/utils/successRequest.js @@ -1,10 +1,10 @@ -'use client' +"use client"; import { toast } from "react-toastify"; import { successToast } from "@/core/components/toasts/success"; export const successRequest = (notification, toastContainer) => { if (notification) { - toast.dismiss({ container: toastContainer }) - successToast(toastContainer) + toast.dismiss({ container: toastContainer }); + successToast(toastContainer); } -} \ No newline at end of file +}; diff --git a/src/core/utils/theme.js b/src/core/utils/theme.js index 581e23e..f32031b 100644 --- a/src/core/utils/theme.js +++ b/src/core/utils/theme.js @@ -1,22 +1,22 @@ -'use client' +"use client"; import { createTheme } from "@mui/material"; const theme = createTheme({ - direction: 'rtl', + direction: "rtl", typography: { fontFamily: `IRANSansFaNum, sans-serif`, - fontSize: 12 + fontSize: 12, }, palette: { primary: { - main: '#2070af', - contrastText: '#fff' + main: "#2070af", + contrastText: "#fff", }, primary2: { - main: '#015688', - contrastText: '#fff' + main: "#015688", + contrastText: "#fff", }, - } + }, }); -export default theme \ No newline at end of file +export default theme; diff --git a/src/core/utils/utils.js b/src/core/utils/utils.js index 98e0252..a0a320d 100644 --- a/src/core/utils/utils.js +++ b/src/core/utils/utils.js @@ -1,162 +1,120 @@ import { alpha, darken } from "@mui/material"; -export const parseCSSVarId = (id) => id.replace(/[^a-zA-Z0-9]/g, '_'); +export const parseCSSVarId = (id) => id.replace(/[^a-zA-Z0-9]/g, "_"); -export const parseFromValuesOrFunc = ( - fn, - arg -) => (fn instanceof Function ? fn(arg) : fn); +export const parseFromValuesOrFunc = (fn, arg) => (fn instanceof Function ? fn(arg) : fn); -export const getCommonToolbarStyles = ({ - table, -}) => ({ - alignItems: 'flex-start', - backgroundColor: table.options.mrtTheme.baseBackgroundColor, - display: 'grid', - flexWrap: 'wrap-reverse', - minHeight: '3.5rem', - overflow: 'hidden', - position: 'relative', - transition: 'all 150ms ease-in-out', - zIndex: 1, +export const getCommonToolbarStyles = ({ table }) => ({ + alignItems: "flex-start", + backgroundColor: table.options.mrtTheme.baseBackgroundColor, + display: "grid", + flexWrap: "wrap-reverse", + minHeight: "3.5rem", + overflow: "hidden", + position: "relative", + transition: "all 150ms ease-in-out", + zIndex: 1, }); -export const getCommonTooltipProps = ( - placement, -) => ({ - disableInteractive: true, - enterDelay: 500, - enterNextDelay: 500, - placement, +export const getCommonTooltipProps = (placement) => ({ + disableInteractive: true, + enterDelay: 500, + enterNextDelay: 500, + placement, }); export const flipIconStyles = (theme) => - theme.direction === 'rtl' - ? { style: { transform: 'scaleX(-1)' } } - : undefined; + theme.direction === "rtl" ? { style: { transform: "scaleX(-1)" } } : undefined; -export const getCommonPinnedCellStyles = ({ - column, - table, - theme, -}) => { - const { baseBackgroundColor } = table.options.mrtTheme; - const isPinned = column?.getIsPinned(); +export const getCommonPinnedCellStyles = ({ column, table, theme }) => { + const { baseBackgroundColor } = table.options.mrtTheme; + const isPinned = column?.getIsPinned(); - return { - '&[data-pinned="true"]': { - '&:before': { - backgroundColor: alpha( - darken( - baseBackgroundColor, - theme.palette.mode === 'dark' ? 0.05 : 0.01, - ), - 0.97, - ), - boxShadow: column - ? isPinned === 'left' && column.getIsLastColumn(isPinned) - ? `-4px 0 4px -4px ${alpha(theme.palette.grey[700], 0.5)} inset` - : isPinned === 'right' && column.getIsFirstColumn(isPinned) - ? `4px 0 4px -4px ${alpha(theme.palette.grey[700], 0.5)} inset` - : undefined - : undefined, - ...commonCellBeforeAfterStyles, - }, - }, - }; + return { + '&[data-pinned="true"]': { + "&:before": { + backgroundColor: alpha(darken(baseBackgroundColor, theme.palette.mode === "dark" ? 0.05 : 0.01), 0.97), + boxShadow: column + ? isPinned === "left" && column.getIsLastColumn(isPinned) + ? `-4px 0 4px -4px ${alpha(theme.palette.grey[700], 0.5)} inset` + : isPinned === "right" && column.getIsFirstColumn(isPinned) + ? `4px 0 4px -4px ${alpha(theme.palette.grey[700], 0.5)} inset` + : undefined + : undefined, + ...commonCellBeforeAfterStyles, + }, + }, + }; }; -export const getCommonMRTCellStyles = ({ - column, - header, - table, - tableCellProps, - theme, -}) => { - const { - getState, - options: { enableColumnVirtualization, layoutMode }, - } = table; - const { draggingColumn } = getState(); - const { columnDef } = column; - const { columnDefType } = columnDef; +export const getCommonMRTCellStyles = ({ column, header, table, tableCellProps, theme }) => { + const { + getState, + options: { enableColumnVirtualization, layoutMode }, + } = table; + const { draggingColumn } = getState(); + const { columnDef } = column; + const { columnDefType } = columnDef; - const isColumnPinned = - columnDef.columnDefType !== 'group' && column.getIsPinned(); + const isColumnPinned = columnDef.columnDefType !== "group" && column.getIsPinned(); - const widthStyles = { - minWidth: `max(calc(var(--${header ? 'header' : 'col'}-${parseCSSVarId( - header?.id ?? column.id, - )}-size) * 1px), ${columnDef.minSize ?? 30}px)`, - width: `calc(var(--${header ? 'header' : 'col'}-${parseCSSVarId( - header?.id ?? column.id, - )}-size) * 1px)`, - }; + const widthStyles = { + minWidth: `max(calc(var(--${header ? "header" : "col"}-${parseCSSVarId( + header?.id ?? column.id + )}-size) * 1px), ${columnDef.minSize ?? 30}px)`, + width: `calc(var(--${header ? "header" : "col"}-${parseCSSVarId(header?.id ?? column.id)}-size) * 1px)`, + }; - if (layoutMode === 'grid') { - widthStyles.flex = `${[0, false].includes(columnDef.grow) - ? 0 - : `var(--${header ? 'header' : 'col'}-${parseCSSVarId( - header?.id ?? column.id, - )}-size)` - } 0 auto`; - } else if (layoutMode === 'grid-no-grow') { - widthStyles.flex = `${+(columnDef.grow || 0)} 0 auto`; - } - - const pinnedStyles = isColumnPinned - ? { - ...getCommonPinnedCellStyles({ column, table, theme }), - left: - isColumnPinned === 'left' - ? `${column.getStart('left')}px` - : undefined, - opacity: 0.97, - position: 'sticky', - right: - isColumnPinned === 'right' - ? `${column.getAfter('right')}px` - : undefined, + if (layoutMode === "grid") { + widthStyles.flex = `${ + [0, false].includes(columnDef.grow) + ? 0 + : `var(--${header ? "header" : "col"}-${parseCSSVarId(header?.id ?? column.id)}-size)` + } 0 auto`; + } else if (layoutMode === "grid-no-grow") { + widthStyles.flex = `${+(columnDef.grow || 0)} 0 auto`; } - : {}; - return { - backgroundColor: 'inherit', - backgroundImage: 'inherit', - display: layoutMode?.startsWith('grid') ? 'flex' : undefined, - justifyContent: - columnDefType === 'group' - ? 'center' - : layoutMode?.startsWith('grid') - ? tableCellProps.align - : undefined, - opacity: - table.getState().draggingColumn?.id === column.id || - table.getState().hoveredColumn?.id === column.id - ? 0.5 - : 1, - position: 'relative', - transition: enableColumnVirtualization - ? 'none' - : `padding 150ms ease-in-out`, - zIndex: - column.getIsResizing() || draggingColumn?.id === column.id - ? 2 - : columnDefType !== 'group' && isColumnPinned - ? 1 - : 0, - ...pinnedStyles, - ...widthStyles, - ...(parseFromValuesOrFunc(tableCellProps?.sx, theme)), - }; + const pinnedStyles = isColumnPinned + ? { + ...getCommonPinnedCellStyles({ column, table, theme }), + left: isColumnPinned === "left" ? `${column.getStart("left")}px` : undefined, + opacity: 0.97, + position: "sticky", + right: isColumnPinned === "right" ? `${column.getAfter("right")}px` : undefined, + } + : {}; + + return { + backgroundColor: "inherit", + backgroundImage: "inherit", + display: layoutMode?.startsWith("grid") ? "flex" : undefined, + justifyContent: + columnDefType === "group" ? "center" : layoutMode?.startsWith("grid") ? tableCellProps.align : undefined, + opacity: + table.getState().draggingColumn?.id === column.id || table.getState().hoveredColumn?.id === column.id + ? 0.5 + : 1, + position: "relative", + transition: enableColumnVirtualization ? "none" : `padding 150ms ease-in-out`, + zIndex: + column.getIsResizing() || draggingColumn?.id === column.id + ? 2 + : columnDefType !== "group" && isColumnPinned + ? 1 + : 0, + ...pinnedStyles, + ...widthStyles, + ...parseFromValuesOrFunc(tableCellProps?.sx, theme), + }; }; export const commonCellBeforeAfterStyles = { - content: '""', - height: '100%', - left: 0, - position: 'absolute', - top: 0, - width: '100%', - zIndex: -1, -}; \ No newline at end of file + content: '""', + height: "100%", + left: 0, + position: "absolute", + top: 0, + width: "100%", + zIndex: -1, +}; diff --git a/src/lib/contexts/DataTable.js b/src/lib/contexts/DataTable.js index 975b859..fb03fd7 100644 --- a/src/lib/contexts/DataTable.js +++ b/src/lib/contexts/DataTable.js @@ -1,15 +1,11 @@ -import {createContext, useState} from "react"; +import { createContext, useState } from "react"; export const DataTableContext = createContext(); -const DataTableProvider = ({children}) => { +const DataTableProvider = ({ children }) => { const [filterData, setFilterData] = useState({}); - return ( - - {children} - - ); + return {children}; }; -export default DataTableProvider; \ No newline at end of file +export default DataTableProvider; diff --git a/src/lib/contexts/auth.js b/src/lib/contexts/auth.js index e60f413..f2df0e6 100644 --- a/src/lib/contexts/auth.js +++ b/src/lib/contexts/auth.js @@ -1,12 +1,12 @@ -'use client' -import { createContext, useCallback, useContext, useEffect, useReducer } from 'react'; -import useRequest from '../hooks/useRequest'; -import { GET_USER_ROUTE } from '@/core/utils/routes'; +"use client"; +import { createContext, useCallback, useContext, useEffect, useReducer } from "react"; +import useRequest from "../hooks/useRequest"; +import { GET_USER_ROUTE } from "@/core/utils/routes"; const initAuth = { initAuthState: false, isAuth: false, - user: {} + user: {}, }; const authReducer = (state, action) => { @@ -28,7 +28,7 @@ const AuthContext = createContext(); export const AuthProvider = ({ children }) => { const [state, dispatch] = useReducer(authReducer, initAuth); - const request = useRequest() + const request = useRequest(); const clearUser = useCallback(() => { dispatch({ type: "CLEAR_USER" }); @@ -48,7 +48,7 @@ export const AuthProvider = ({ children }) => { const getUser = useCallback(async () => { try { - const { data } = await request(GET_USER_ROUTE, 'get') + const { data } = await request(GET_USER_ROUTE, "get"); changeUser(data); changeAuthState(true); changeInitAuth(true); @@ -62,15 +62,21 @@ export const AuthProvider = ({ children }) => { }, [clearUser, changeUser, changeAuthState, changeInitAuth]); useEffect(() => { - getUser() - }, []) + getUser(); + }, []); - return {children}; + return ( + + {children} + + ); }; -export const useAuth = () => useContext(AuthContext); \ No newline at end of file +export const useAuth = () => useContext(AuthContext); diff --git a/src/lib/contexts/tableSetting.js b/src/lib/contexts/tableSetting.js index abc2ad7..3611df9 100644 --- a/src/lib/contexts/tableSetting.js +++ b/src/lib/contexts/tableSetting.js @@ -1,26 +1,26 @@ -'use client' -import {createContext, useCallback, useEffect, useState} from "react"; +"use client"; +import { createContext, useCallback, useEffect, useState } from "react"; export const TableSettingContext = createContext(); -export const TableSettingProvider = ({children}) => { +export const TableSettingProvider = ({ children }) => { const [settingStore, setSettingStore] = useState({}); useEffect(() => { - const _localStorage = localStorage.getItem("_setting-app") + const _localStorage = localStorage.getItem("_setting-app"); if (_localStorage) { - setSettingStore(JSON.parse(_localStorage)) + setSettingStore(JSON.parse(_localStorage)); } }, []); const hideAction = useCallback((user_id, page_name, table_name, settingValue, columns) => { updateSettingStorage(user_id, page_name, table_name, "hides", settingValue, columns); - }, []) + }, []); const sortAction = useCallback((user_id, page_name, table_name, settingValue, columns) => { updateSettingStorage(user_id, page_name, table_name, "sorts", settingValue, columns); - }, []) + }, []); const filterAction = (user_id, page_name, table_name, settingValue, columns) => { updateSettingStorage(user_id, page_name, table_name, "filters", settingValue, columns); - } + }; const updateSettingStorage = (user_id, page_name, table_name, settingType, settingValue, columns) => { const prevLocalStorage = JSON.parse(localStorage.getItem("_setting-app")) || {}; const userSettings = prevLocalStorage[user_id] || {}; @@ -30,7 +30,7 @@ export const TableSettingProvider = ({children}) => { if (settingType === "sorts" || settingType === "filters") { newSettings = [...settingValue]; } else { - newSettings = {...tableSettings[settingType] || {}, ...settingValue}; + newSettings = { ...(tableSettings[settingType] || {}), ...settingValue }; } const updatedLocalStorage = { ...prevLocalStorage, @@ -40,18 +40,21 @@ export const TableSettingProvider = ({children}) => { ...pageSettings, [table_name]: { ...tableSettings, - [settingType]: Array.isArray(settingValue) ? [...newSettings] : {...newSettings}, - summary: SummaryTextMessage({ - ...tableSettings, - [settingType]: Array.isArray(settingValue) ? [...newSettings] : {...newSettings}, - }, columns) + [settingType]: Array.isArray(settingValue) ? [...newSettings] : { ...newSettings }, + summary: SummaryTextMessage( + { + ...tableSettings, + [settingType]: Array.isArray(settingValue) ? [...newSettings] : { ...newSettings }, + }, + columns + ), }, }, }, }; localStorage.setItem("_setting-app", JSON.stringify(updatedLocalStorage)); setSettingStore(updatedLocalStorage); - } + }; const refactorAction = (user_id, page_name, table_name) => { const prevLocalStorage = JSON.parse(localStorage.getItem("_setting-app")) || {}; const userSettings = prevLocalStorage[user_id] || {}; @@ -68,7 +71,7 @@ export const TableSettingProvider = ({children}) => { }; localStorage.setItem("_setting-app", JSON.stringify(refactorData)); setSettingStore(refactorData); - } + }; const SummaryTextMessage = (values, columns) => { let SummaryText = ""; let HideText = ""; @@ -76,38 +79,35 @@ export const TableSettingProvider = ({children}) => { let SortText = ""; if (values.sorts && values.sorts.length > 0) { - const _list = [] + const _list = []; for (const sort of values.sorts) { - const _column = columns.find(column => column.id == sort.id) - if (_column) - _list.push(`${_column.header}` + `(${sort.desc ? "نزولی" : "صعودی"})`) + const _column = columns.find((column) => column.id == sort.id); + if (_column) _list.push(`${_column.header}` + `(${sort.desc ? "نزولی" : "صعودی"})`); } - if (_list.length > 0) - SortText = " مرتب شده بر اساس : " + _list.join(", ") + if (_list.length > 0) SortText = " مرتب شده بر اساس : " + _list.join(", "); } if (values.filters && values.filters.length > 0) { - const _list = [] + const _list = []; for (const filter of values.filters) { - const _column = columns.find(column => column.id == filter.id) - if (_column) - _list.push(`${_column.header}`) + const _column = columns.find((column) => column.id == filter.id); + if (_column) _list.push(`${_column.header}`); } - if (_list.length > 0) - FilterText = " فیلتر شده بر اساس : " + _list.join(", ") + if (_list.length > 0) FilterText = " فیلتر شده بر اساس : " + _list.join(", "); } if (values.hides) { - const hidesArray = Object.entries(values.hides).map((e) => ({id: e[0], value: e[1]})) + const hidesArray = Object.entries(values.hides).map((e) => ({ + id: e[0], + value: e[1], + })); if (hidesArray.length > 0) { - const _list = [] + const _list = []; for (const hide of hidesArray) { - if (hide.value) continue - const _column = columns.find(c => c.id == hide.id) - if (_column) - _list.push(_column.header) + if (hide.value) continue; + const _column = columns.find((c) => c.id == hide.id); + if (_column) _list.push(_column.header); } - if (_list.length > 0) - HideText = "ستون های مخفی شده : " + _list.join(", "); + if (_list.length > 0) HideText = "ستون های مخفی شده : " + _list.join(", "); } } @@ -128,7 +128,7 @@ export const TableSettingProvider = ({children}) => { } } if (FilterText) { - SummaryText += FilterText + SummaryText += FilterText; } } @@ -137,8 +137,15 @@ export const TableSettingProvider = ({children}) => { return ( + value={{ + settingStore, + hideAction, + sortAction, + filterAction, + refactorAction, + }} + > {children} ); -}; \ No newline at end of file +}; diff --git a/src/lib/hooks/useDataTable.js b/src/lib/hooks/useDataTable.js index ba7acb5..e396908 100644 --- a/src/lib/hooks/useDataTable.js +++ b/src/lib/hooks/useDataTable.js @@ -1,9 +1,9 @@ -import {useContext} from "react"; -import {DataTableContext} from "@/lib/contexts/DataTable"; +import { useContext } from "react"; +import { DataTableContext } from "@/lib/contexts/DataTable"; const useTableSetting = () => { - const {filterData, setFilterData} = useContext(DataTableContext); - return {filterData, setFilterData}; + const { filterData, setFilterData } = useContext(DataTableContext); + return { filterData, setFilterData }; }; export default useTableSetting; diff --git a/src/lib/hooks/useRequest.js b/src/lib/hooks/useRequest.js index 8beee2e..2e35512 100644 --- a/src/lib/hooks/useRequest.js +++ b/src/lib/hooks/useRequest.js @@ -5,38 +5,42 @@ import axios from "axios"; const defaultOptions = { data: {}, requestOptions: { - headers: {} + headers: {}, }, notification: { show: true, success: false, - failed: true + failed: true, }, -} +}; const useRequest = (initOptions) => { const _options = Object.assign({}, defaultOptions, initOptions); - return async (url = '', method = 'get', options) => { + return async (url = "", method = "get", options) => { const mergedOptions = Object.assign({}, _options, options); try { const response = await axios({ url, method, - data: method === 'get' ? null : mergedOptions.data, + data: method === "get" ? null : mergedOptions.data, withCredentials: true, - ...mergedOptions.requestOptions + ...mergedOptions.requestOptions, }); - successRequest(mergedOptions.notification.show && mergedOptions.notification.success, 'request_data'); + successRequest(mergedOptions.notification.show && mergedOptions.notification.success, "request_data"); return response; } catch (error) { if (error.response) { - errorResponse(error.response, mergedOptions.notification.show && mergedOptions.notification.failed, 'request_data'); + errorResponse( + error.response, + mergedOptions.notification.show && mergedOptions.notification.failed, + "request_data" + ); } throw error; } - } -} + }; +}; -export default useRequest \ No newline at end of file +export default useRequest; diff --git a/src/lib/hooks/useTableSetting.js b/src/lib/hooks/useTableSetting.js index 7617655..6588446 100644 --- a/src/lib/hooks/useTableSetting.js +++ b/src/lib/hooks/useTableSetting.js @@ -1,10 +1,9 @@ -import {useContext} from "react"; -import {TableSettingContext} from "../contexts/tableSetting"; +import { useContext } from "react"; +import { TableSettingContext } from "../contexts/tableSetting"; const useTableSetting = () => { - const {settingStore, hideAction, sortAction, filterAction, refactorAction} = - useContext(TableSettingContext); - return {settingStore, hideAction, sortAction, filterAction, refactorAction}; + const { settingStore, hideAction, sortAction, filterAction, refactorAction } = useContext(TableSettingContext); + return { settingStore, hideAction, sortAction, filterAction, refactorAction }; }; export default useTableSetting;